Movement.md (1004B)
1 # Movement 2 3 CS 331 W12 L1 4 5 There are many different ways to implement movement. 6 7 A common way to move is by doing this: 8 9 ```csharp 10 11 float speed = 2.0f; //assign default movement speed 12 float rotationRate = 30.0f; //assign default rate of rotation 13 14 bool moveForward = Input.GetKey("up"); 15 if (moveForward){ 16 transform.position += transform.forward * speed * Time.deltaTime; 17 } 18 19 bool rotateLeft = Input.GetKey("left"); //this assumes rotation is done by keyboard input 20 if(rotateLeft){ 21 transform.Rotate(0, -rotationRate * Time.deltaTime, 0); 22 } 23 ``` 24 The issue with this is movement may not feel natural because there is no acceleration being applied to the object you are just moving it by a certain amount. In essence, you are assigning a velocity to the object for the frames where the "up" key is pressed. 25 26 See [Input](Input.md) for more information about the Input class. 27 28 See [Vector3](Vector3.md) for more information about positions. 29 30 See [Quaternions](Quaternions.md) for more about rotation/angles