- Home /
left and right 2d walk
Hi I am newer to scripting and I have a question about 2d movement. Originally this script I got from a tornado twins youtube video. I edited it so it would not rotate a character.
pragma strict
function Start () {
}
var speed : float = 3;
var rotateSpeed : float = 3;
function Update() { var controller : CharacterController = GetComponent( CharacterController );
var forward = transform.TransformDirection( Vector3.forward );
var curSpeed = speed * Input.GetAxis( "Vertical" );
controller.SimpleMove( forward * curSpeed );
}
@script RequireComponent( CharacterController );
The only problem is that I walk with up and down instead of left and right. Is there a solution?
Answer by Lovrenc · Jan 12, 2013 at 12:50 AM
Rotate your character or fix position in modeling program when you are exporting.
Note in unity:
Z is forrward,
Y is up,
X is right.
So when you are moving by calling
Vector3.forward
you will move on Z axis.
found the problem. Ins$$anonymous$$d of var curSpeed = speed * Input.GetAxis( "Vertical" ); i needed to use horizontal
Your answer
![](https://koobas.hobune.stream/wayback/20220613090811im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D game movement/jump issue 2 Answers
Problem creating a 2D scroller shooting game 2 Answers
(Solved) Continuous movement 1 Answer
how can i touch the fast objects ? 0 Answers