- Home /
Unity Car Tutorial Rotate Snippet Chaos
So, i took this little code snippet from the Unity's Car Tutorial to rotate my 2D Car Game Wheels, for accurate rotation:
w.wheelVelo = rigidbody.GetPointVelocity(wh.point);
w.groundSpeed = w.wheelGraphic.InverseTransformDirection(w.wheelVelo);
print (w.wheelVelo);
print (w.groundSpeed.x);
print (w.groundSpeed.y);
//w.wheelGraphic.Rotate(Vector3.forward * (-w.groundSpeed.x / wheelRadius) * Time.deltaTime * Mathf.Rad2Deg);
And in the Debug the values printed look like so:
(13.8, 0.0, 0.0) 13.80005 -0.00028884
(17.2, 0.0, 0.0) 17.20007 -0.0003456686
Looking perfect for a 2D game being left, right (x-axis), up, down (y-axis), so whats the problem...... The catch is that the rotate part is actually commented
If the comment is removed these are the values returned:
(19.4, 0.0, 0.0) 3.437649E-05 19.40008
(20.9, 0.0, 0.0) 4.99693E-05 20.90008
And guess what it doesn't end there if i change the groundspeed from .x to .y like so to fix that bug in value:
w.wheelGraphic.Rotate(Vector3.forward * (-w.groundSpeed.y / wheelRadius) * Time.deltaTime * Mathf.Rad2Deg);
Guess what, you guessed right, the values returned are now are :
(15.7, 0.0, 0.0) 15.70005 -0.005213013
(16.7, 0.0, 0.0) -16.70006 -0.001558624
So, where does this leave us, to WTF, and me hoping im blind to something cause ive been scripting the whole day, trying hard to believe that that is no hidden unity button thats called F-Over user for some fun, and trying even harder not to say UNITY is F-IN STUPID.
Any help, insight to this wonderful encounter to Unity's Daily Coding Shafts as i would like to call it, probably fit for a YouTube Series name, it would be really great :)
Until then have a great day, and please find a way this is reported to Unity Developers
Thanks
Your answer
Follow this Question
Related Questions
Script gives wrong rotation. 1 Answer
Disabling the Z axis? 1 Answer
2D camera rotating relatively to game object speed 0 Answers