Advertisement
MyroC137

ship

May 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SpaceShipControlAttempt : MonoBehaviour {
  6.  
  7. float distance = 0f;
  8.  
  9. void Awake()
  10. {
  11. Quaternion rot = Camera.main.transform.rotation;
  12. GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
  13. }
  14.  
  15. void Update () {
  16. GameObject player = GameObject.Find("Player");
  17. Camera.main.transform.localEulerAngles = new Vector3(15f, 0, 0);
  18. Camera.main.transform.localPosition = new Vector3(0, 5, -7);
  19.  
  20. player.transform.localEulerAngles = new Vector3(0, 0, 0);
  21. player.transform.localPosition = new Vector3(0, 1, 1);
  22.  
  23. if (Input.GetKey("z"))
  24. {
  25. if (distance < 100f)
  26. {
  27. distance += 0.1f;
  28. print(distance);
  29. }
  30.  
  31. transform.position += Camera.main.transform.forward * distance * Time.deltaTime;
  32. }
  33. else if (Input.GetKey("x"))
  34. {
  35. if (distance > -100)
  36. {
  37. distance -= 0.1f;
  38. }
  39. transform.position += Camera.main.transform.forward * distance * Time.deltaTime;
  40. }
  41. else
  42. {
  43. if(distance > 0)
  44. {
  45. distance -= 0.1f;
  46. }
  47. if(distance < 0)
  48. {
  49. distance += 0.1f;
  50. }
  51. transform.position += Camera.main.transform.forward * distance * Time.deltaTime;
  52. }
  53.  
  54. // Rotations based on w, a, s, d keys
  55.  
  56. if (Input.GetKey("w"))
  57. {
  58. GetComponent<Rigidbody>().AddTorque(transform.right * Time.deltaTime * 2000f);
  59. }
  60.  
  61. if (Input.GetKey("s"))
  62. {
  63. GetComponent<Rigidbody>().AddTorque(-transform.right * Time.deltaTime * 2000f);
  64. }
  65.  
  66. if (Input.GetKey("a"))
  67. {
  68. GetComponent<Rigidbody>().AddTorque(0, 0, 2000f * Time.deltaTime);
  69. }
  70.  
  71. if (Input.GetKey("d"))
  72. {
  73. GetComponent<Rigidbody>().AddTorque(0, 0, -2000f * Time.deltaTime);
  74. }
  75.  
  76. if (Input.GetKey("q"))
  77. {
  78. GetComponent<Rigidbody>().AddTorque(-transform.up * Time.deltaTime * 2000f);
  79. }
  80.  
  81. if (Input.GetKey("e"))
  82. {
  83. GetComponent<Rigidbody>().AddTorque(transform.up * Time.deltaTime * 2000f);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement