How to make object move and stop
Hi ! I'm starting making my first game.But I don't know how to make player move like Move forward : W Move backward : S Move to left : A Move to right : D
And how to make a player stop moving ?
Can anyone help me ?
Thank you @SamuelOliver123
Answer by armandowildframemedia · Nov 30, 2017 at 10:05 AM
Hello there! Those are some basic things about Input sampling and Transform/rigidbody operations. My recommendation would be that you take a look at this nice Unity tutorial which explain how to move an object with physics: https://unity3d.com/es/learn/tutorials/s/roll-ball-tutorial
It will help you understand the basics of Input and movement in Unity.
Also, if you just want to move the character object with keypresses, you can create a component like:
public class MoveWASD : MonoBehaviour {
public float moveSpeed;
void Update () {
transform.Translate (
new Vector3 { x = Input.GetAxis ("Horizontal"), z = Input.GetAxis ("Vertical") }
* moveSpeed
* Time.deltaTime
);
}
}
That just translates the object at a speed that you can set in the inspector. The W and S keys are associated to the Vertical axis in the Unity Input, and the A and D keys to the Horizontal axis.