Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. //Right click to move script
  2.  
  3. //must eventually use this as an interrupt for the attack mode script, moving must
  4. // disengage attack mode unless the target is in front of the player. otherwise you could
  5. // just fly away and shoot lasers out of your ass.
  6.  
  7. private var targetPosition:Vector3;
  8.  
  9. function Update () {
  10.  
  11. // get the speed variable
  12. var engine : myEngine;
  13. engine = gameObject.GetComponent("myEngine");
  14.  
  15. if(Input.GetKey(KeyCode.Mouse1))
  16. //so that only when the key is pressed is the ship moving
  17. {
  18.  
  19. var playerPlane = new Plane(Vector3.up, transform.position);
  20. var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  21. var hitdist = 0.0;
  22.  
  23. if (playerPlane.Raycast (ray, hitdist)) {
  24. var targetPoint = ray.GetPoint(hitdist);
  25. targetPosition = ray.GetPoint(hitdist);
  26. var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
  27. transform.rotation = targetRotation;
  28. }
  29. }
  30.  
  31. transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * engine.speed);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement