Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The `else if` is the problem. With the `else if`, it **wont** run the rest of the code in the else if any one in the top is true. What you do is **remove** the else ifs and simply use multiple if statements.
- private void MovePlayer()
- {
- if (Input.GetKey(KeyCode.W)) // Up
- {
- if (Input.GetKey(KeyCode.A)) //Up and left
- {
- rigidB.velocity += new Vector3(-moveSpeed, 0, moveSpeed);
- }
- else if (Input.GetKey(KeyCode.D)) //Up and right
- {
- rigidB.velocity += new Vector3(moveSpeed, 0, moveSpeed);
- }
- else
- {
- rigidB.velocity += new Vector3(0, 0, moveSpeed);
- }
- }
- if (Input.GetKey(KeyCode.S)) // Down
- {
- rigidB.velocity += new Vector3(0, 0, -moveSpeed);
- }
- if (Input.GetKey(KeyCode.A)) // Left
- {
- rigidB.velocity += new Vector3(-moveSpeed, 0, 0);
- }
- if (Input.GetKey(KeyCode.D)) // Right
- {
- rigidB.velocity += new Vector3(moveSpeed, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment