Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //IDLE STATE
- if (state == PlayerState.Idle) {
- if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown (KeyCode.D) || Input.GetKeyDown (KeyCode.A)) {
- SetMovingState ();
- }
- }
- //MOVING STATE
- else if (state == PlayerState.Move) {
- targetDirection.Set (0, 0, 0);
- if (Input.GetKey (KeyCode.W)) {
- targetDirection.z += 1.0f;
- forwardSpeed = speed;
- }
- if (Input.GetKey (KeyCode.S)) {
- targetDirection.z -= 1.0f;
- forwardSpeed = speed;
- }
- if (Input.GetKey (KeyCode.D)) {
- targetDirection.x += 1.0f;
- forwardSpeed = speed;
- }
- if (Input.GetKey (KeyCode.A)) {
- targetDirection.x -= 1.0f;
- forwardSpeed = speed;
- }
- if (targetDirection.x == 0.0f && targetDirection.z == 0.0f) {
- SetDampingSate ();
- return;
- }
- targetRotation = Quaternion.LookRotation (targetDirection);
- rigidBody.MoveRotation (Quaternion.Slerp (transform.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
- rigidBody.MovePosition (transform.position + transform.forward * forwardSpeed * Time.fixedDeltaTime);
- }
- //DAMPING STATE
- else if (state == PlayerState.Damping) {
- if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown (KeyCode.D) || Input.GetKeyDown (KeyCode.A)) {
- SetMovingState ();
- return;
- }
- forwardSpeed = Mathf.Lerp (forwardSpeed, 0, dampingSpeed * Time.fixedDeltaTime);
- if (forwardSpeed <= 0.1f) {
- SetIdleState ();
- return;
- }
- rigidBody.MovePosition (transform.position + transform.forward * forwardSpeed * Time.fixedDeltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement