Getting navAgent.velocity is NaN

CaptCanada

New member
HI all

I posted this question in the Unity/Scripting forums but haven't gotten and answer there so I thought I would try and post it here.

I am using Unity 2018.3.8f1 and BD 1.6.2.

I have a script, based on the MecWarriors MecAnim and navmesh tutorial, that I have attached to an Agent.

Here is the code:

Code:
using UnityEngine;
using System.Collections;
using BehaviorDesigner.Runtime;
//using UnityEngine.AI.NavMeshAgent;


public class MovementScript : MonoBehaviour
{
    //link to Animator component
    public Animator animController;
    //used to set anim controller parameters
    public enum MoveState { Idle,Walking,Attack}
    public MoveState moveState;
    //link to NavMeshAgent component
    public UnityEngine.AI.NavMeshAgent navAgent;
    public BehaviorTree behaviorTree;
    private bool canSeePlayer;
    private bool canAttack;
    public float damageAmount;
  

    public void Start()
    
    {
        canSeePlayer = ((SharedBool)behaviorTree.GetVariable("Chase")).Value;
        canAttack = ((SharedBool)behaviorTree.GetVariable("Attack")).Value;             
      
    }
    
    // Update is called once per frame
    void Update()
    {
        //character walks if there is a navigation path set, idle all other times
        canSeePlayer = ((SharedBool)behaviorTree.GetVariable("Chase")).Value;
        canAttack = ((SharedBool)behaviorTree.GetVariable("Attack")).Value;
        


        if (canSeePlayer)

        {
            moveState = MoveState.Walking;
            print(moveState);
            print("I see you!");

            if (canAttack)
            {
                print("Attacking you!");
                moveState = MoveState.Attack;

            }


        }
        else
        {
            moveState = MoveState.Walking;
        }
                
        //send move state info to animator controller
        animController.SetInteger("MoveState", (int)moveState);

    }
    void OnAnimatorMove()
    {
        //only perform if walking
        if (moveState == MoveState.Walking)
        {
            print("In OnAnimatorMove Function");
            //set the navAgent's velocity to the velocity of the animation clip currently playing
            navAgent.velocity = animController.deltaPosition / Time.deltaTime;
            //smoothly rotate the character in the desired direction of motion
            Quaternion lookRotation = Quaternion.LookRotation(navAgent.desiredVelocity);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, navAgent.angularSpeed * Time.deltaTime);
        }
    }

    

}

Here is the error that is generated:

navmeshagent.velocity assign attempt for 'creature1' is not valid. Input velocity is { NaN, NaN, NaN }.
UnityEngine.AI.NavMeshAgent:set_velocity(Vector3)
MovementScript:OnAnimatorMove() (at Assets/Scipts/MovementScript.cs:71)

When I comment out the line affected, the agent moves according to the behavior tree but the animation playing and the agent's movement are rather "fast" and not very convincing.

I've used this script before in Unity 2017.3 with the same behavior tree and the same model. I am not sure why I am getting the error and have tried adjust the Seek Task Speed variable to a value higher than the one in the NavMeshAgent Speed variable.

Here is the tree I am using:
1203

Thanks for any help/tips/kick in the pants! you guys can provide
 
Top