- Home /
transform.Translate not translating in relation to rotation
I am unable to understand why my gameObject will not move in the direction that it has been rotated.
if (Input.GetAxis("Vertical") > 0)
{
transform.position += transform.forward * throttle * Time.deltaTime * Input.GetAxis("Vertical");
}
float turn = rotspeed * Time.deltaTime * Input.GetAxisRaw("Turn");
transform.Rotate(0, turn, 0);
Any help would be appreciated, Joshua O
By all accounts it should work just fine. I'll post the movement script I usually use. $$anonymous$$aybe it will work for you.
void FixedUpdate() {
// Handle the $$anonymous$$ovement
Handle$$anonymous$$ovement ();
// Handle the Rotation
HandleRotation ()
}
void Handle$$anonymous$$ovement () {
var h = Input.GetAxis("Horizontal");
var v = Input.GetAxis("Vertical");
var move = new Vector3(h, 0, v);
transform.position = Vector3.Lerp (transform.position, transform.position + move * throttle * Time.DeltaTime, 1f);
}
void HandleRotation () {
var h = horizontalSpeed * Input.GetAxis("$$anonymous$$ouse X");
transform.Rotate(Qauternion.Euler(0, h, 0));
}
$$anonymous$$y script did work just fine, it seems Unity? (Visual Studio?) didn't update the last amendment I made to the code which is what you see there. I really don't know why it update. I am certain I saved the code prior to switching back to unity, as I do that in every case I am looking for a different result.
If you have any idea why Unity may not update, that would probabaly help me a lot more.
And Btw, ty kindly for the feedback and personal work example :D I will store it for reference later.
Joshua O
Your answer
![](https://koobas.hobune.stream/wayback/20220612184240im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Moving an object 1 Answer
Move terrain towards object? (illusion of moving forward) 1 Answer
move another object when 2 other objects collide 1 Answer
The gizmo is not at center of object 0 Answers