- Home /
How can I rotate an object without moving it up or down?
This is my code there, i have an aircraft, it has a rigidbody component with no gravity(i have some constraints) the movement is good but when i try to rotate it left or right, it's rotating and increasing/decreasing its height. What can I do?
public class Movement : MonoBehaviour
{
private Rigidbody rg;
// Start is called before the first frame update
void Start()
{
rg = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rg.transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
rg.transform.Rotate(Vector3.back * Input.acceleration.x * 2f);
}
}
Comment
Your answer
Follow this Question
Related Questions
managing rotation of Turret on two axis 1 Answer
Delayed rotation when i use transform.rotate 1 Answer
Strange rotation pattern. 0 Answers
How to reset child object's rotation without changing parent's 1 Answer
When applying a 90 degree rotation to Euler Angles, it is over/undershooting sometimes.. 2 Answers