Hey,This wolf will run up there. Is there any way to solve this? Thank you




image

The wolf is floating atop the others? Does it always float at that height, or just when the wolves are bunched together?

Can you provide screenshots of the Box Collider? If I don’t see anything particularly wrong, I will try to recreate this behavior on my end and see what the solution is.

image

thank you reply

Hmm, I don’t seem able to replicate this issue with your settings. Two quick questions:

  1. Does your Monster script make any changes to the unit’s positions?
  2. What version of Astar Pathfinding and Unity do you have installed?

monster script
using Mirror;
using Pathfinding;
using Pathfinding.RVO;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.PlayerLoop;

public class Monster : NetworkBehaviour
{

public Transform uiposition;
public Animator _animator;
private AIDestinationSetter aIDestinationSetter;
private AIPath aiPath;
private RVOController rvoController;

public int ID;//
private float sightRadius;
private bool blFoundPlayer = false;
private GameObject Target;//目标对象
float hp_boost_times = 0f;
float attackTime = 0;
bool isAttack = false;
// Start is called before the first frame update
void Start()
{
    _animator = GetComponent<Animator>();

        gameObject.AddComponent<Seeker>();

        rvoController = gameObject.GetComponent<RVOController>();
        aIDestinationSetter = gameObject.AddComponent<AIDestinationSetter>();
        aiPath = gameObject.AddComponent<AIPath>();
        gameObject.AddComponent<SimpleSmoothModifier>();
        aiPath.maxSpeed = monster_info.MoveSpeed;
        aiPath.endReachedDistance = 0.8f;
        aiPath.pickNextWaypointDist = 5f;
        aiPath.slowdownDistance = 1f;
        aiPath.enableRotation = false;

        rvoController.enabled = true;

        sightRadius = 5f;
    
}

Vector3 PickRandomPoint()
{
    if (Vector3.Distance(transform.position, spawn.Position) > 20)//超过50米回来
    {
        return spawn.Position;
    }
    var point = Random.insideUnitSphere * 10;
    point.y = 0;
    point += aiPath.position;
    return point;
}
public void FoundPlayer()
{
    var colliders = Physics.OverlapSphere(transform.position, sightRadius);
    foreach (var item in colliders)
    {
        if (item.CompareTag("Player") && item.GetComponent<Player>().player_hp > 0)
        {
            Target = item.gameObject;
            transform.LookAt(new Vector3(Target.transform.position.x, transform.position.y, Target.transform.position.z));
            aiPath.maxSpeed = monster_info.MoveSpeed;

            //Debug.Log("发现玩家");
            blFoundPlayer = true;
            return;
        }
    }
    Target = null;
    blFoundPlayer = false;
    isAttack = false;
    attackTime = 0;
}


/// <summary>
/// 受到伤害
/// </summary>
public void OnDamage(GameObject attacker, long damage)
{
    float hurt = damage - monster_info.Defense;
    if (hurt > 0)
    {
        hp = hp - hurt;
    }

    if (hp < 0.01)
    {
        _animator.SetBool("iswalk", false);
        _animator.SetBool("isdead", true);
        aiPath.enabled = false;
        aIDestinationSetter.enabled = false;

        Invoke("Dead", 5);
        
    }
}



void Dead()
{
    NetworkServer.Destroy(gameObject);
}

private void Attack()
{
    if (Target == null)
        return;
    Player player = Target.GetComponent<Player>();
    if (player.player_hp > 0)
    {
        player.OnDamage(this.gameObject, monster_info.Attack);
    }
    else
    {
        isAttack = false;
        attackTime = 0;
    }

}
void Update()
{
    if (hp < 0.01)
    {
        if (!_animator.GetBool("isdead"))
        {
            _animator.SetBool("isdead", true);
        }
        if (!isServer && UIBarObj != null && NetworkClient.active)
        {
            gameObject.GetComponent<BoxCollider>().enabled = false;
            // Debug.Log("Monster Dead");

        }
        return;
    }


    if (isAttack)
    {
        attackTime += Time.deltaTime;
        if (attackTime < 3)
            return;
        else
        {
            attackTime = 0;
            isAttack = false;
            aiPath.SetPath(null);
        }

    }


    if (blFoundPlayer)
    {
        if (Target == null)
        {
            blFoundPlayer = false;
            return;
        }
        float fd = Vector3.Distance(transform.position, Target.transform.position);
        //  Debug.Log("与玩家距离:" + fd);

        //如果跟玩家的y轴相差很多

        if (!aiPath.pathPending && fd <= aiPath.endReachedDistance)
        {
            aiPath.SetPath(null);
            _animator.SetBool("iswalk", false);

            isAttack = true;
            attackTime = 0;

            Attack();

        }
        else if (!aiPath.pathPending)
        {
            //检查是否在攻击
            aiPath.destination = Target.transform.position;
            transform.LookAt(new Vector3(Target.transform.position.x, transform.position.y, Target.transform.position.z));
           
            aiPath.SearchPath();
            if (!_animator.GetBool("iswalk"))
            {
                _animator.SetBool("iswalk", true);
            }
        }
    }
    else
    {
        if (!aiPath.hasPath || aiPath.reachedDestination || aiPath.remainingDistance < aiPath.endReachedDistance)
        {
            RandomPath randPath = RandomPath.Construct(transform.position, 10000);
            randPath.spread = 3000;

            aiPath.SetPath(randPath);
            transform.LookAt(new Vector3(aiPath.endOfPath.x, transform.position.y, aiPath.endOfPath.z));
          
            if (!_animator.GetBool("iswalk"))
            {
                _animator.SetBool("iswalk", true);
            }
        }
        else
        {
            transform.LookAt(new Vector3(aiPath.endOfPath.x, transform.position.y, aiPath.endOfPath.z));
        }

    }

    FoundPlayer();

GameManagerServer.instance.npcMovePoints[moveIndex].transform.position;

    // Vector3 forward = transform.TransformDirection(Vector3.forward);
    // transform.rotation = Quaternion.LookRotation(forward);
    //  transform.eulerAngles = new Vector3(0.0f,  direction.z, 0.0f);
}








public void MonsterAttack()
{

    _animator.SetBool("iswalk", false);
    _animator.SetBool("isattack", true);
}

public void StartMove()
{

    if (!_animator.GetBool("walk"))
    {
        _animator.SetBool("attack", false);
        // gameObject.GetComponent<NetworkAnimator>().SetTrigger()
        _animator.SetBool("walk", true);
    }
}

public void EndMove()
{
    _animator.SetBool("attack", false);
    _animator.SetBool("walk", false);

}

}

Your AIPath script has its Raycast Ground Mask set to Everything. That will make it detect other agents as ground. Try to put the agents on a separate layer, and exclude that from the mask.


Solved, thanks for your help,

thanks for your help,