Silverbullets

unity exosuit movement script

Jun 11th, 2015
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Movement : MonoBehaviour {
  5.     public float maxSpeed = 5.0f;
  6.     public float speed;
  7.     public float speedScalar = 1.25f;
  8.     public float decelScalar = 3.0f;
  9.     public float gravity = 20.0f;
  10.     public float angleSpeed = 1.05f;
  11.     Vector3 movDirection;
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.         speed = 0.0f;
  16.         movDirection = transform.right;
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         //Vector3 curPos = transform.position;
  23.         /*Movement Combinations:
  24.          * XY - forward
  25.          * AB - backward
  26.          * XB - right
  27.          * AY - left */
  28.         if (Input.GetButton("X") && Input.GetButton("Y"))
  29.         {
  30.             //Acceleration handling
  31.             if (speed > -5.0f)
  32.             {
  33.                 speed -= speedScalar * Time.deltaTime;
  34.             }
  35.         }
  36.         else if (Input.GetButton("A") && Input.GetButton("B"))
  37.         {
  38.             //Backward acceleration handling
  39.             if (speed < 5.0f)
  40.             {
  41.                 speed += speedScalar * Time.deltaTime;
  42.             }
  43.         }
  44.         else
  45.         {
  46.             if (speed < 1.0f && speed > -1.0f)
  47.             {
  48.                 speed = 0.0f;
  49.             }
  50.             else if (speed < -1.0f)
  51.             {
  52.                 speed += decelScalar * Time.deltaTime;
  53.             }
  54.             else if (speed > 1.0f)
  55.             {
  56.                 speed -= decelScalar * Time.deltaTime;
  57.             }
  58.         }
  59.         if (Input.GetButton("X") && Input.GetButton("B"))
  60.         {
  61.             transform.rotation = transform.rotation * Quaternion.AngleAxis(angleSpeed, Vector3.forward);
  62.         }
  63.         if (Input.GetButton("A") && Input.GetButton("Y"))
  64.         {
  65.             //Turn left
  66.             transform.rotation = transform.rotation * Quaternion.AngleAxis(angleSpeed, Vector3.back);
  67.         }
  68.         transform.Translate(movDirection * Time.deltaTime * speed);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment