For third-person games, the protagonist usually adds a character controller to control the movement. It's time to simulate gravity and let the hero stand on the floor. If you use a D control around, W s control before and after, then the control mobile code can write:
Public classMove:monobehaviour { PublicCharactercontroller character; Public floatSpeed ; //Use this for initialization voidStart () {character= This. Getcomponent<charactercontroller>(); speed=1f; } //Update is called once per frame voidUpdate () {floatHorizontal = Input.getaxis ("Horizontal");//A D or so floatVertical = Input.getaxis ("Vertical");//W S up and down floatMovey =0; floatGravity =-9.8f; Movey= gravity*Time.deltatime; Character. Move (NewVector3 (horizontal, Movey, vertical) * speed *time.deltatime); }}
Use the Input.getaxis method to get the following default axes: "Horizontal" and "Vertical" are mapped to the joystick, A, W, S, D, and arrow keys (direction keys). Horizontal and verical are two numbers between [ -1,1] respectively. With this code, the characters move only on the XZ plane.
You can also use transform to move. Translate method, or use rigidbody and give the rigid body speed. But one thing to note is that if the move command is inside the update () function, the object moves with jitter, because each frame time is not fixed and the distance traveled is long and short. The solution to this problem is to write the move statement in the Fixedupdate () function, because the length of each frame of the function is fixed.
Specific other mobile methods can be seen http://www.jianshu.com/p/5653b0be5fd4
Character movement in the Unity3d