Hi, I had another thread about this, but it was all getting a little confusing so I’m reposting for unity
Joystick2.js
Movement Joy.js
function Update () {
var force = Vector3.up * Joystick2.vertical + Vector3.right * Joystick2.horizontal;
rigidbody.AddForce(force);
}
Getting an error of rigidbody.force assign attempt for ‘Player 1’ is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Rigidbody:AddForce(Vector3) - reasably sure it’s to do with the “horizontal = vertical = 0;” line, but I’m unsure on how to fix.
It’s hard to say for sure, but I’d guess that somewhere along the line you’re accidentally attempting an illegal math operation – for example, if you divide by zero in Interpolate().
I’d suggest that you double check all of your inputs. Did you set all of those inspector values on your scene objects? If any of those are left at zero, you’ll get some strange results.
If that’s not it, you might step through your script as it runs and try to find where the numbers start going awry. Attach a debugger, if you can, or use Debug.Log() to check your math results as you go.
Once you figure out the specific line that’s erroring out, you should have a much better idea of how to proceed.
I had a similar error with invalid assignment to a rigidbody.velocity = infinity, NaN, NaN. Turns out I forgot to rename the enemy player AI projectile rotation amount variable to another name that is different from my main player. Look for shared variables.