- 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 You! · Jan 12, 2013 at 01:35 AM
You need to get your input from the "Horizontal" axis instead of the "Vertical" one.
Vertical = up/down
Horizontal = left/right (like the horizon)
To add on, use Input.GetAxis ("Horizontal") or "Vertical". Also, these values gradually grow to magnitude of 1.0, which adds in a nice progressive movement. If you want instant reaction use Input.Get$$anonymous$$ey(). For vertical movement you will want to decide whether you want Get$$anonymous$$ey or Get$$anonymous$$eyDown
Your answer
Follow this Question
Related Questions
animation 2d platformer 2 Answers
2D Platformer Mouse aiming! 0 Answers
Editing Character Motor 2 Answers
2D Sidescroller: Change camera position? 1 Answer
A 2D toolkit animation question 0 Answers