- Home /
troble with the Axis in unity
I was making a 2.5d game in unity everything was working correctly but when I tried to rotate the Character it stopped working. What I did in my game was if I was rotated facing +z then I would move forward but when I pressed "a" then it should turn around and move in the opposite direction but instead it turns around and starts walking backward. I don't think that it was my script can someone please help me.
here is my script
` var speed : float;
function Update() { var fwd : Vector3 = Vector3.forward; var controller : CharacterController = GetComponent(CharacterController);
if(Input.GetKey("d")) { controller.transform.rotation.y = 0; controller.Move(fwd speed Time.deltaTime); } if(Input.GetKey("a")) { controller.transform.rotation.y = 180; controller.Move(fwd speed Time.deltaTime); } } `
Answer by Anxo · Nov 02, 2012 at 09:09 PM
your forward is pointing forward in world space not in object space. So it does not care if you rotate the character, you are still telling it to go forward in world space. You can either make the fwd var relative to the characters facting direction by saying fwd = transform.forward or you can tell A to move (fwd* speed Time.deltatime)-1
Your answer
Follow this Question
Related Questions
OnTriggerEnter not working 0 Answers
Character Animation Wont Play 2 Answers
A node in a childnode? 1 Answer
Material not loading 0 Answers