- Home /
Solved | Rotating Object in Single Axis while staying Perpendicular to a Rotating Plane
I seem to be having an issue with rotating the player object in the Y-Axis while staying perpendicular to a rotating ground plane.
I tried keeping the player as a separate object and matching current rotation with the ground rotation and replaced the Y-Axis, as well as a child object of the Ground. When manipulating the Y-Axis separately it causes it to detach from the plane. In the editor I can rotate child objects while staying perpendicular, though in run-time it's different.
Answer by Chimer0s · Apr 08, 2018 at 10:10 PM
Do you have a rigidbody attached to the player? If so, that will cause it to move independently of the Ground. This can be handled by making the rigidbody kinematic/turning off gravity. If you're not using a rigidbody, the easiest way to do what you're attempting is to have the player as a child of the Ground and rotate it along the (local) Y-axis. Make sure that you're affecting it's local rotation specifically.
Depending on how you're doing it, the code would look something like:
player.transform.localEulerAngles = new Vector3(player.transform.localEulerAngles.x, desiredYRot, player.transform.localEulerAngles.z);
or
player.transform.Rotate(player.transform.up * Time.deltaTime);
If you share the code you're currently working with, it might be easier to give a more specific answer to your case.
I recently just found a solution to use transform.Rotate(new Vector3(0,y,0)). This also works, thanks also showing me this method. I had a feeling it there might be a local rotation function, but couldn't find a post addressing this specifically
Your answer
Follow this Question
Related Questions
How can I multiply the rotation of a mirrored object? 1 Answer
Rotating 2D sprite to match surface. 0 Answers
Place object on radius pointing to a other object 1 Answer
Vector3.Slerp normal 1 Answer