Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour
- {
- [Range(0.1f, 200.0f)]
- public float movementSpeed;
- [Range(0.1f, 200.0f)]
- public float maxSpeed;
- [Range(0.8f, 0.9999f)]
- public float movementSlowdown;
- private Rigidbody body;
- void Start()
- {
- body = this.GetComponent<Rigidbody>();
- }
- void Update()
- {
- Vector3 movementVector = Vector3.zero;
- if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
- {
- movementVector += this.transform.forward;
- }
- else if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
- {
- movementVector += -this.transform.forward;
- }
- if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
- {
- movementVector += -this.transform.right;
- }
- else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
- {
- movementVector += this.transform.right;
- }
- if(body.velocity.magnitude < maxSpeed)
- {
- if (movementVector != Vector3.zero)
- {
- body.AddForce(movementVector * movementSpeed);
- }
- }
- Debug.DrawLine(this.transform.position, this.transform.position + this.transform.forward * 5.0f, Color.magenta);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement