- Home /
How do you perform multiple rotations on the same object? - (in a single frame)
Hi,
I'm trying to perform the two following rotations on a single object without them conflicting:
The player will rotate the character on the local Y axis using the camera. Allowing the player to run forward in the direction of the camera. (The camera is a child of the character)
The artificial gravity will rotate the character to so that it's head points outward, from the center of the planet. The Y rotation is often changed to accomplish this.
I can easily do either rotation but as soon as I try to perform both, everything fails horrendously.
Vector math and Quaternions have always given me a lot of trouble conceptually. Anyone willing to teach would be greatly appreciated!
Edit: I'm trying to combine this:
var targetCharacterOrientation = Quaternion.FromToRotation(characterBody.transform.up, upDirection) * characterBody.transform.rotation;
With this:
var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, targetCharacterOrientation * Vector3.up);
characterBody.transform.rotation = yRotation * targetCharacterOrientation;
The first rotation is changing the Y rotation value and so is the second (yRotation). I need to use X and Z from the first rotation but Y from the second. I tried using Euler angles but ran into Gimbal lock.
Hi @yotingo
I'm not sure what you mean by $$anonymous$$ching - You didn't show any code of yours. It might just be that you've done something incorrectly. What you describe should be doable.
The question is also bit vague; You seem to have some sort of $$anonymous$$i-planet perhaps? But you fail to show image or explain your reason for changing gravity direction.
Also, you probably are not doing this "player will rotate the character on the local Y axis using the camera" - as you mention that camera is child of player?
Thatnks for the reply! I've updated my question with more details.
Your answer
Follow this Question
Related Questions
Player not facing the mouse correctly 1 Answer
Rotating wrong 0 Answers
Using xbox controller with top down shooter 0 Answers
Bullet flies away for no apparent reason. 1 Answer
Help with hold x,y,z rotation 1 Answer