- Home /
rotating Character 90 degrees in relation to world and move in direction.
I am taking a unity class in school and i may have made my project a bit overly ambitious. Essentially I am taking an old 2D side scroller game and trying to make it in 3D. Therefore my character can move left and right. forward and backwards on platforms. But i need my characters to turn exactly 90degrees in Y (no inbetweens) to face the left and right and exactly 180 degrees to face back. I've tried transform.Rotate(0,90,0) and transform.Rotate(0,-90,0) but it doesn't take into account if my character has faced left twice (and now is facing back) and I now want it to face forwards. Is there a way of making sure that the character faces left side of the world when the it turns left and the right side of the world when it turns right. And the same for front and back. ( i am using the wasd keys to control the characters movements),
Answer by CmdrZin · Dec 18, 2020 at 09:11 AM
You could try setting up four Quaternion rotations and just set the transform.rotation to one of the four.
see https://docs.unity3d.com/ScriptReference/Transform-rotation.html
@CmdrZin wow...I felt really dumb. Thank you for pointing me in the right direction. I've been staring at the code for hours and i finally got it!
Answer by mei_huang · Dec 18, 2020 at 12:39 PM
@CmdrZin Do you have an example of how you would set up for quaternion rotation? O_O I tried it using transform.rotation = Quaternion.Euler(transform.rotation.x, -90, transform.rotation.z) and so on for all the directions, and while my player rotates like i want them to, i know Quaternion messes with the numbers making it go all crazy and my player stops being able to move.
No, but look at https://docs.unity3d.com/ScriptReference/Quaternion.html
for other possabilities and https://docs.unity3d.com/$$anonymous$$anual/QuaternionAndEulerRotationsInUnity.html
Your answer
Follow this Question
Related Questions
Rotating player with Quaternion and RotateTowards 1 Answer
The character controller stop moving when the Speed Start increase Endless runner 0 Answers
Character will not go from Ide to Walk 1 Answer
Rotate the character movement with the character 1 Answer
Enemy follow/chase behaviour glitching when using rotateTowards 0 Answers