Advertisement
Guest User

Untitled

a guest
Aug 25th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. Vector3 dir = targetPos - transform.position;
  2. if(dir.x >= 0) dir.x = Mathf.Min(dir.x , dir.x - Screen.width);
  3. else dir.x = Mathf.Max(dir.x , dir.x + Screen.width);
  4.  
  5. if(dir.y >= 0) dir.y = Mathf.Min(dir.y , dir.y - Screen.height);
  6. else dir.y = Mathf.Max(dir.y , dir.y + Screen.height);
  7.  
  8. float rotZ = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
  9.  
  10. transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0,0,-rotZ), rotationSpeed);
  11.  
  12. rb.AddForceAtPosition(transform.up * Thrust, transform.position - transform.up);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement