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 SpaceShipControlAttempt : MonoBehaviour {
- float distance = 0f;
- void Awake()
- {
- Quaternion rot = Camera.main.transform.rotation;
- GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
- }
- void Update () {
- GameObject player = GameObject.Find("Player");
- Camera.main.transform.localEulerAngles = new Vector3(15f, 0, 0);
- Camera.main.transform.localPosition = new Vector3(0, 5, -7);
- player.transform.localEulerAngles = new Vector3(0, 0, 0);
- player.transform.localPosition = new Vector3(0, 1, 1);
- if (Input.GetKey("z"))
- {
- if (distance < 100f)
- {
- distance += 0.1f;
- print(distance);
- }
- transform.position += Camera.main.transform.forward * distance * Time.deltaTime;
- }
- else if (Input.GetKey("x"))
- {
- if (distance > -100)
- {
- distance -= 0.1f;
- }
- transform.position += Camera.main.transform.forward * distance * Time.deltaTime;
- }
- else
- {
- if(distance > 0)
- {
- distance -= 0.1f;
- }
- if(distance < 0)
- {
- distance += 0.1f;
- }
- transform.position += Camera.main.transform.forward * distance * Time.deltaTime;
- }
- // Rotations based on w, a, s, d keys
- if (Input.GetKey("w"))
- {
- GetComponent<Rigidbody>().AddTorque(transform.right * Time.deltaTime * 2000f);
- }
- if (Input.GetKey("s"))
- {
- GetComponent<Rigidbody>().AddTorque(-transform.right * Time.deltaTime * 2000f);
- }
- if (Input.GetKey("a"))
- {
- GetComponent<Rigidbody>().AddTorque(0, 0, 2000f * Time.deltaTime);
- }
- if (Input.GetKey("d"))
- {
- GetComponent<Rigidbody>().AddTorque(0, 0, -2000f * Time.deltaTime);
- }
- if (Input.GetKey("q"))
- {
- GetComponent<Rigidbody>().AddTorque(-transform.up * Time.deltaTime * 2000f);
- }
- if (Input.GetKey("e"))
- {
- GetComponent<Rigidbody>().AddTorque(transform.up * Time.deltaTime * 2000f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement