Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Movement : MonoBehaviour {
- public float maxSpeed = 5.0f;
- public float speed;
- public float speedScalar = 1.25f;
- public float decelScalar = 3.0f;
- public float gravity = 20.0f;
- public float angleSpeed = 1.05f;
- Vector3 movDirection;
- // Use this for initialization
- void Start () {
- speed = 0.0f;
- movDirection = transform.right;
- }
- // Update is called once per frame
- void Update()
- {
- //Vector3 curPos = transform.position;
- /*Movement Combinations:
- * XY - forward
- * AB - backward
- * XB - right
- * AY - left */
- if (Input.GetButton("X") && Input.GetButton("Y"))
- {
- //Acceleration handling
- if (speed > -5.0f)
- {
- speed -= speedScalar * Time.deltaTime;
- }
- }
- else if (Input.GetButton("A") && Input.GetButton("B"))
- {
- //Backward acceleration handling
- if (speed < 5.0f)
- {
- speed += speedScalar * Time.deltaTime;
- }
- }
- else
- {
- if (speed < 1.0f && speed > -1.0f)
- {
- speed = 0.0f;
- }
- else if (speed < -1.0f)
- {
- speed += decelScalar * Time.deltaTime;
- }
- else if (speed > 1.0f)
- {
- speed -= decelScalar * Time.deltaTime;
- }
- }
- if (Input.GetButton("X") && Input.GetButton("B"))
- {
- transform.rotation = transform.rotation * Quaternion.AngleAxis(angleSpeed, Vector3.forward);
- }
- if (Input.GetButton("A") && Input.GetButton("Y"))
- {
- //Turn left
- transform.rotation = transform.rotation * Quaternion.AngleAxis(angleSpeed, Vector3.back);
- }
- transform.Translate(movDirection * Time.deltaTime * speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment