Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CaptCanada · Apr 29, 2019 at 06:54 PM · error message

navAgent.velocity input returns NaN

Hi all

Here is a script I have attached to a navAgent to navigate a mesh. using UnityEngine; using System.Collections; using BehaviorDesigner.Runtime; using UnityEngine.AI;

 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 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()
     {
         navAgent.updateRotation = false;
         //only perform if walking
         if (moveState == MoveState.Walking)
         {
             print("In OnAnimatorMove Function");
             print(navAgent.velocity);
             //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);
         }
     }
 
     
 
 }
 

I am getting an error in the navAgent.velocity=animController.deltaPosition/Time.deltaTime; line saying that the navAgent.velocity is NaN

I am not sure what is causing this and need some help.

Thanks

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Apr 29, 2019 at 07:23 PM 0
Share

From the docs:

Animator.applyRoot$$anonymous$$otion must be enabled for deltaPosition to be calculated


Are you applying root motion with your Animator? If not, that is probably your NaN.

avatar image metalted · Apr 30, 2019 at 02:55 PM 0
Share

On line 68ish you are dividing the velocity by deltaTime. Dividing by 0 will give nan. Save the assignment to a variable first, check if it is 0. Don't know why deltatime would be 0, but it's the only nan source i can find.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CaptCanada · Apr 30, 2019 at 02:13 PM

I read the docs in your link and it mentions that when using OnAnimatorMove(), that Animator.applyRootMotion won't have an effect.

I am using OnAnimatorMove() in my script.

link text

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

108 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Could not preload global game manager #0 0 Answers

Health Script Help...? 1 Answer

"No appropriate version" error 2 Answers

Implicit downcast from 'Object[]' to 'UnityEngine.GUITexture[]' 1 Answer

SetPixels32 called with invalid number if pixels in the array 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges