Home > Blockchain >  rigidbody.velocity assign attempt for 'gameobject' is not valid. Input velocity is {NaN, N
rigidbody.velocity assign attempt for 'gameobject' is not valid. Input velocity is {NaN, N

Time:02-11

I am working on a game in Unity and I am currently getting this error when pulling up my menu.

Here is the script

private void OnAnimatorMove()
    {
        float delta = Time.deltaTime;
        enemyManager.enemyRigidBody.drag = 0;
        Vector3 deltaPosition = anim.deltaPosition;
        deltaPosition.y = 0;
        Vector3 velocity = deltaPosition / delta;
        enemyManager.enemyRigidBody.velocity = velocity;


    }

CodePudding user response:

Sounds like OnAnimatorMove is also being called outside of PlayMode where Time.deltaTime most probably is simply 0

=> division by 0 => generally not a good thing to do ;)

You could probably avoid that by checking

private void OnAnimatorMove()
{
    if(! Application.isPlaying) return;

    ...
}

or maybe

if(Mathf.Approximately(Time.deltaTime, 0f)) return;

Also see this thread

  • Related