Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class playerControl : MonoBehaviour
- {
- public float rotationSpeed;
- public float maxForwardAcceleration;
- public float maxBackwardAcceleration;
- public float maxStrafeAcceleration;
- public float maxClimbAcceleration;
- public float maxBoostAcceleration;
- public float forwardAcceleration;
- public float boostAcceleration;
- public float backwardAcceleration;
- public float strafeAcceleration;
- public float climbAcceleration;
- private float boost;
- public float forward;
- private float backward;
- private float left;
- private float right;
- private float up;
- private float down;
- void FixedUpdate()
- {
- float pitch = Input.GetAxis("Pitch") * rotationSpeed * Time.fixedDeltaTime;
- float yaw = Input.GetAxis("Yaw") * rotationSpeed * Time.fixedDeltaTime;
- float roll = Input.GetAxisRaw("Roll") * rotationSpeed * Time.fixedDeltaTime;
- //Move forward if under speed limit
- if (forward < maxForwardAcceleration)
- {
- forward += Input.GetAxisRaw("Forward") * forwardAcceleration * Time.fixedDeltaTime;
- }
- //Move backward if under speed limit
- if (backward < maxBackwardAcceleration)
- {
- backward += Input.GetAxisRaw("Backward") * backwardAcceleration * Time.fixedDeltaTime;
- }
- //Move left if under speed limit
- if (left < maxStrafeAcceleration)
- {
- left += Input.GetAxisRaw("Left") * strafeAcceleration * Time.fixedDeltaTime;
- }
- //Move right if under speed limit
- if (right < maxStrafeAcceleration)
- {
- right += Input.GetAxisRaw("Right") * strafeAcceleration * Time.fixedDeltaTime;
- }
- //Move up if under speed limit
- if (up < maxStrafeAcceleration)
- {
- up += Input.GetAxisRaw("Up") * climbAcceleration * Time.fixedDeltaTime;
- }
- //Move down if under speed limit
- if (down < maxStrafeAcceleration)
- {
- down += Input.GetAxisRaw("Down") * climbAcceleration * Time.fixedDeltaTime;
- }
- //Boost
- if (boost < maxBoostAcceleration && Input.GetAxisRaw("Forward") > 0)
- {
- boost += Input.GetAxisRaw("Boost") * boostAcceleration * Time.fixedDeltaTime;
- }
- //Slows if forward key is released
- if (Input.GetAxisRaw("Forward") < 1 && forward > 0)
- {
- forward = 0;
- }
- //Slows if backward key is released
- if (Input.GetAxisRaw("Backward") < 1 && backward > 0)
- {
- backward = 0;
- }
- //Slows if left key is released
- if (Input.GetAxisRaw("Left") < 1 && left > 0)
- {
- left = 0;
- }
- //Slows if right key is released
- if (Input.GetAxisRaw("Right") < 1 && right > 0)
- {
- right = 0;
- }
- //Slows if up key is released
- if (Input.GetAxisRaw("Up") < 1 && up > 0)
- {
- up = 0;
- }
- //Slows if down key is released
- if (Input.GetAxisRaw("Down") < 1 && down > 0)
- {
- down = 0;
- }
- //Slows if boost key is released
- if (Input.GetAxisRaw("Boost") < 1 && boost > 0)
- {
- boost = 0;
- }
- rigidbody.AddRelativeTorque(pitch, yaw, roll);
- rigidbody.AddRelativeForce(Vector3.forward * forward);
- rigidbody.AddRelativeForce(Vector3.back * backward);
- rigidbody.AddRelativeForce(Vector3.left * left);
- rigidbody.AddRelativeForce(Vector3.right * right);
- rigidbody.AddRelativeForce(Vector3.up * up);
- rigidbody.AddRelativeForce(Vector3.down * down);
- rigidbody.AddRelativeForce(Vector3.forward * boost);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement