MovementControls
How do I use Movement Controls
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
46 | MovementControls(); | 1 |
71 | void MovementControls() | 2 |
File name: PlayerControl.cs
Copy
71 void MovementControls()
72 {
73 float screenSpeed = 0;
74 float horizontalInput = 0;
75 float verticalInput = 0;
76
77 screenSpeed = CameraMotor.speedScreen;
78
79 //moving right
80 if (Input.GetKey(KeyCode.D))
81 horizontalInput = speedCurrent;
82
83 //moving left
84 if (Input.GetKey(KeyCode.A))
85 horizontalInput = -speedCurrent;
86
87 //moving up
88 if (Input.GetKey(KeyCode.W))
89 verticalInput = speedCurrent;
90
91 //moving down
92 if (Input.GetKey(KeyCode.S))
93 verticalInput = -speedCurrent;
94
95
96 //result velocity
97 rb.velocity = new Vector3(horizontalInput, 0, screenSpeed + verticalInput);
98 }
MovementControls 114 lượt xem
Gõ tìm kiếm nhanh...