- Home /
Error with transform.RotateAround when I use a variable for the last parameter...
Hi there! Another day, another seemingly strange and unsolvable problem...
I'm setting up the rotations for the planets in a space exploration game. I've got the planets rotated to various inclinations and I've got them rotating around their local 'up' axes. But....
Each planet has a _rotationAdjustment float which represents the amount of degrees the planet should rotate per second. I'm using:
transform.RotateAround( Vector3.zero, _rotationAxis, _rotationAdjustment * Time.deltaTime );
...which works fine, but when I test the game it's throwing the following error:
transform.position assign attempt for '' is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Transform:RotateAround(Vector3, Vector3, Single)
Which seems to do nothing but slow the game down, which is annoying. When I replace the _rotationAdjustment variable with a literal value, say -0.02, I don't get the error. I have Debug.Log-ed _rotationAdjustment at various places, and it always displays as a valid value (NOT NaN or infinity, for example).
Oddly, the error message gives the third parameter as a 'single', but Unity didn't recognise that type when I tried (single)_rotationAdjustment.
Any idea what's happening here? And if not, is there a different transform method I can use to rotate around an axis?
Cheers.
I can't duplicate it, but: notice how it's angry about the new position being illegal, so I think you're on the right track -- you're computing using impossible values. Is _rotationAxis
ever all 0's (which should be an error, but my Unity5.2.1 simply does nothing.)
I believe Single is just another word for float. Error messages don't always use consistent terms.
Answer by taylank · Jan 07, 2016 at 09:00 PM
Can't think why you're having that error, but here is a link to how to do RotateAround without using the transform function: http://answers.unity3d.com/questions/489350/rotatearound-without-transform.html
The C# version of the code is in the comments area.
From the OP's 3rd-from-the-bottom Para: " I have Debug.Log-ed _rotationAdjustment at various places, and it always displays as a valid value (NOT NaN or infinity, for example)."
We try to move Qs from users that need basic help into the HelpRoom area. I left this Q in main UA since it seems like it might be a real-ish problem.
Your answer
Follow this Question
Related Questions
Resetting transform's original position and rotation after using transform.rotateAround 1 Answer
Ball Rolling Animation Not Working Properly 0 Answers
Orbit around orbiting object (transform.RotateAround) 1 Answer
How to rotate an object around a screen point (mousePosition)? 1 Answer
RotateAround Limitations 2 Answers