- Home /
How to make the character rotate
I am trying to make an AirPlane in my game. I have a script that make it move forward ALL the time, which makes the game more realistic. BUT i wanted to also rotate the plane with A and D to Left and Right. The problem is that i don't know how to make this... How do i rotate an object with rigidbody to left and right in script?
Answer by Glurth · Oct 24, 2016 at 08:30 PM
You want to use the object's transform.localRotation (https://docs.unity3d.com/ScriptReference/Transform-localRotation.html)
You an assign an left/right angle as a rotation around the Y-axis like so: gameObject.tranform.localRotataion= Quaternion.Eulers(0,angle,0); (https://docs.unity3d.com/ScriptReference/Quaternion.html)
A positive angle will rotate it one direction, a negative angle will rotate it the other direction.
Note: as you rotate the plane, it's FORWARD direction of motion should probably change too! If so, make sure to use the transform's forward direction for your motion: gameObject.transform.forward defines the direction the transform is facing. (https://docs.unity3d.com/ScriptReference/Transform-forward.html)
Answer by Robak · Oct 24, 2016 at 10:03 PM
https://docs.unity3d.com/ScriptReference/Transform.Rotate.html
I know somthing only about 2d. There is 2 way to do it. airplane.transform.rotation(vector 3) and airplane.transform.rotate(x,y,z) in first object move all the time by vector 3 given in parameter function second one rotete 1 time airplane to parameters in function
Next time give more information. Is your game 2d or 3d etc.
Are you sure you read my question? Clearly not.
Why do i have to say if my game is 2D or 3D if i already said "it moves forward and i want to know how to move it sideways". You can't do this in 2d.
Also, the link doesn't match. That doc is referencing how to move a gameobject from time to time ins$$anonymous$$d of using inputs like A and D.
Your answer
Follow this Question
Related Questions
How can I slowly rotate a sprite to face its movement direction? 1 Answer
How can I introduce a turning function for my player in this script? 1 Answer
how to make a detect rotation script for negative rotation too 2 Answers
Object modified in script not modified in scene 0 Answers
How i get my cloud position in other script? I want to use this temp value in other script. 1 Answer