- Home /
How to move a object in relation to relative rotation
How do I move an object in the direction it is facing no matter where it is facing?
I am making an airplane, and I need it to move in the direction I am looking.
I tried to send this earlier but its got deleted...dont know why...
this.gameObject.transform.position += transform.forward Time.deltaTime runMovementSpeed;
Answer by SeddyTSG · Apr 17, 2021 at 10:35 AM
You can do that with transform.forward:
this.gameObject.transform.position += transform.forward * Time.deltaTime * movementSpeed;
Answer by SeddyTSG · Apr 17, 2021 at 07:51 AM
this.gameObject.transform.position += transform.forward Time.deltaTime movementSpeed;
Answer by eplaygame · Apr 17, 2021 at 12:24 PM
If You use physics, try this:
public float speed;
public Rigidbody rb;
private void FixedUpdate()
{
rb.velocity = transform.forward * speed;
}
Or You can change position directly without physics:
public float speed;
private void Update()
{
transform.Translate(transform.forward * speed * Time.deltaTime);
}
Check if your object with the movement script has blue arrow (Z-axis) in the direction correct direction.
Your answer
Follow this Question
Related Questions
I want to disable character movement and camera movement while certain animation is playing 1 Answer
isGrounded is always false, even with gravity, how do you fix that? 1 Answer
Slowly move a GameObject on 1 axis, then destroy it. 1 Answer
2D Topdown Character Contoller 0 Answers
Slime script? 1 Answer