- Home /
Problem with transform.position
Hello everyone ;)
I have this script:
var Speed : float = 0; var MaxSpeed : float = 10; var Acceleration : float = 10; var Deceleration : float = 10; var rotateSpeed = 25.0; function Update () { if(Input.GetKey("a")) { transform.eulerAngles.y -= rotateSpeed * Time.deltaTime; } if(Input.GetKey("d")) { transform.eulerAngles.y += rotateSpeed * Time.deltaTime; } if ((Input.GetKey ("s"))&&(Speed < MaxSpeed)) { Speed = Speed - Acceleration * Time.deltaTime; } else if ((Input.GetKey ("w"))&&(Speed > -MaxSpeed)) { Speed = Speed + Acceleration * Time.deltaTime; } else { if(Speed > Deceleration * Time.deltaTime) { Speed = Speed - Deceleration * Time.deltaTime; } else if(Speed < -Deceleration * Time.deltaTime) { Speed = Speed + Deceleration * Time.deltaTime; } else { Speed = 0; } }
transform.position.z = transform.position.z + Speed * Time.deltaTime; }
Simple yet quiet effectivt...
The problem is that I want my character to turn, wich I have done using transform.eulerAngles
The problem is that, my character moves along the "World axes" no matter how he turns he will still move in the world z-axes if I press "w" If he faces backwards ind a press w(forward key) he still moves along the world z direction.
So my question is is there a way to get my charcter move along his "Local axes" instead of the "World/global axes"
Answer by Bunny83 · Feb 26, 2011 at 01:13 PM
First: Don't increment or decrement eulerAngles. If they are out of bounds [0..360] you get an error. Use Transform.Rotate instead.
And for the position use localPosition or Translate
Your answer

Follow this Question
Related Questions
Instantiateon custom rotation doesn't work 2 Answers
Vector 3 - move on only one axis 0 Answers
How can I call this player transform.position code once, then stop? 2 Answers
Cannot move or rotate child Object 5 Answers
Move to mouse position 1 Answer