Game Development Reference
In-Depth Information
28.
} else if(Input.GetKey(KeyCode.D)){
29.
//Move right
30.
speed.x = movementSpeed * Time.deltaTime;
31.
} else {
32.
speed.x = 0;
33.
}
34.
35.
if(Input.GetKey(KeyCode.W)){
36.
//Move forward
37.
speed.z = movementSpeed * Time.deltaTime;
38.
} else if(Input.GetKey(KeyCode.S)){
39.
//Move backwards
40.
speed.z = -movementSpeed * Time.deltaTime;
41.
} else {
42.
speed.z = 0;
43.
}
44.
45.
//Read jump input
46.
if(Input.GetKeyDown(KeyCode.Space)){
47.
//Apply jump only if the player is on the ground
48.
if(transform.position.y == 2.0f){
49.
speed.y = jumpSpeed;
50.
}
51.
}
52.
53.
//Move the character
54.
transform.Translate(speed);
55.
56.
//Apply gravity to velocity
57.
if(transform.position.y > 2.0f){
Search WWH ::




Custom Search