- Home /
Rotation not going past 180?
My player wont pass 180 degrees ( clockwise or anti clock wise ), It slows down more and more the closer it gets to 180. if(Input.GetAxis("Horizontal")){ transform.localRotation.y += Time.deltaTime * TurnSpeed;
}
Thanks
How would i keep going past 180? Thanks for reply.
Answer by Bunny83 · Apr 25, 2019 at 09:24 AM
Your script can not work because it has multiple issues:
First of all the most important. localRotation as well as rotation are unit Quaternions, not euler angles. Quaternions are an expansion of complex numbers. The 4 values (x,y,z,w) are in the range -1 to 1 and do not resemble euler angles (3 consecutive rotations around 3 seperate principal axes). Quaternions have many advantages as they do not suffer from Gimbal lock like euler angles. However Quaternions are less intuitive. It actually represents a single 3d rotation axis as well as an angle (not in degree or radians) around that axis.
Second this statement:
transform.localRotation.y += xxx;
doesn't have any effect on the actual rotation since localRotation is a property of a struct. This line does not invoke the setter of the property and therefore does not change the value at all. Note that this line did work in UnityScript. However UnityScript (Unity's Javascript like language) is already deprecated for quite some time now.
Finally keep in mind that even when the rotation part would work, adding constantly to the rotation would rotate your player endlessly.
If you want actual help with your actual problem, it would help when you describe what you actually want to achieve. To actually rotate an object around the y axis in degree you can use transform.Rotate(0, amount, 0);
If you actually want to learn more about quaternions I recommend this Numberphile video on quaternions as a brief introduction. And if you have the time watch the 3b1b series on quaterions
ps: I just noticed you added the "javascript" tag. Does that mean you still use UnityScript? I would highly recommend to switch to C#. The latest Unity versions do not support UnityScript anymore.
Hi, thanks for the answer! transform.Rotate works perfectly. I will definitly use C#, I had no idea about the removal of java.
Answer by K-Anator · Apr 25, 2019 at 05:33 AM
I'm having a hard time figuring out how you're even rotating the character with the given script. From what I can gather, you're just moving them to the right when the player presses down. What style of game is this? Top down? Side scroller? 2D? 3D?
Its a 3d snowboarding game, when he goes left or right he should be able to corner constantly but it just slows down the cornering
Your answer
Follow this Question
Related Questions
Smooth Rotation Help 1 Answer
transform.LookAt overrides rigidbody rotation 0 Answers
How to add random force/Rotation to bulletEject. 1 Answer
Finish a rotation with cube face up. 1 Answer
Make camera 1 transform equal to camera 2 transform 1 Answer