Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ControlShip : MonoBehaviour {
- public int rotationSpeed = 75;
- public int movementspeed = 10;
- private int thrust = 5;
- bool isPKeyDown = false;
- float acceleration = .0f;
- Vector3 previousPosition = Vector3.zero;
- Rigidbody _rigidbody;
- // Use this for initialization
- void Start () {
- _rigidbody = GetComponent<Rigidbody>();
- Debug.Log("Acc Speed: " + thrust);
- }
- // Update is called once per frame
- void Update () {
- //var v3 = new Vector3(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"), 0.0f);
- //transform.Rotate(v3 * rotationSpeed * Time.deltaTime);
- //transform.position += transform.forward * Time.deltaTime * movementspeed; // this can break while calculations ... since its before calculating acceleration
- if (Input.GetKey(KeyCode.Z))
- transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
- if ((isPKeyDown = Input.GetKey("p")))
- {
- float distance = Vector3.Distance(previousPosition, transform.position);
- acceleration = distance / Mathf.Pow(Time.deltaTime, 2);
- _rigidbody.AddRelativeForce(0f, 0f, thrust, ForceMode.Acceleration);
- }
- var v3 = new Vector3(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"), 0.0f);
- transform.Rotate(v3 * rotationSpeed * Time.deltaTime);
- transform.position += transform.forward * Time.deltaTime * movementspeed;
- previousPosition = transform.position;
- }
- void OnGUI()
- {
- if (isPKeyDown)
- {
- GUI.Label(new Rect(100, 100, 200, 200), "Acc Speed: " + acceleration);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement