- Home /
Local-Global error.
I want my character to move on a local axis, but it moves on a global one. How can I fix this?
Impossible to say without knowing how you move your player in the first place.
What's the purpose of this? You could child it to an empty GameObject and use Transform.localPosition and/or Transform.localRotation, but why?
Answer by Berenger · Jun 06, 2012 at 11:05 PM
Don't know how you move, but you might need Space.Self for Translate or TransformDirection.
chicka123 : Oops. Heres the script
var moveSpeed : float;
var turnSpeed : float;
//var jumpForce : float;
function Update(){
if(Input.GetButton("Forward")) {
transform.Translate(transform.forward * moveSpeed * Time.deltaTime);
}
if(Input.GetButton("Backward")) {
transform.Translate(-transform.forward * moveSpeed * Time.deltaTime);
}
if(Input.GetButton("TurnRight")) {
transform.Rotate(transform.up * turnSpeed * Time.deltaTime);
}
if(Input.GetButton("TurnLeft")) {
transform.Rotate(-transform.up * turnSpeed * Time.deltaTime);
}
}
$$anonymous$$e : Comments guys, comments !
Check out Translate's doc, the default Space is Self. If you translate localy of transform.forward, you're applying the rotation twice.
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
// or
transform.Translate(transform.forward * moveSpeed * Time.deltaTime, Space.World);
Your answer
Follow this Question
Related Questions
Rotating Player Controller locally or globally. 0 Answers
use world axis when using transform.rotate 3 Answers
use world axis when using transform.rotate 0 Answers
Can't rotate character in horizontal axis. 2 Answers
How can I align Axis? 0 Answers