TeHArGiS10

Untitled

Aug 6th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class ufoController : MonoBehaviour {
  4.  
  5. public float sensitivity;
  6. public float speed;
  7. Rigidbody rb;
  8.  
  9. void Start ()
  10. {
  11. rb = GetComponent<Rigidbody>();
  12. }
  13.  
  14. void Update ()
  15. {
  16. //Movement
  17. float xPos = Input.GetAxisRaw("Horizontal");
  18. float zPos = Input.GetAxisRaw("Vertical");
  19.  
  20. Vector3 xMov = transform.right * xPos;
  21. Vector3 zMov = transform.forward * zPos;
  22.  
  23. Vector3 velocity = (xMov + zMov).normalized * speed;
  24.  
  25. if (velocity != Vector3.zero)
  26. {
  27. rb.MovePosition(rb.position + velocity * Time.deltaTime);
  28. }
  29.  
  30. //Camera
  31. float xRot = Input.GetAxisRaw("Mouse Y");
  32. float yRot = Input.GetAxisRaw("Mouse X");
  33.  
  34. Vector3 vectorX = new Vector3(xRot, 0, 0) * sensitivity;
  35. Vector3 vectorY = new Vector3(0, yRot, 0) * sensitivity;
  36.  
  37. rb.MoveRotation(rb.rotation * Quaternion.Euler(vectorY));
  38. Camera.main.transform.Rotate(-vectorX);
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment