Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. private var targetPosition:Vector3;
  2.  
  3. function Update () {
  4.  
  5. // get the speed variable
  6. var engine : myEngine;
  7. engine = gameObject.GetComponent("myEngine.speed");
  8.  
  9. if(Input.GetKey(KeyCode.Mouse1))
  10. //so that only when the key is pressed is the ship moving
  11. {
  12.  
  13. var playerPlane = new Plane(Vector3.up, transform.position);
  14. var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  15. var hitdist = 0.0;
  16.  
  17. if (playerPlane.Raycast (ray, hitdist)) {
  18. var targetPoint = ray.GetPoint(hitdist);
  19. targetPosition = ray.GetPoint(hitdist);
  20. var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
  21. transform.rotation = targetRotation;
  22. }
  23. }
  24.  
  25. transform.position = Vector3.MoveTowards (transform.position, targetPosition, Time.deltaTime * engine.speed);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement