Advertisement
dasmalle

move around sphere

Apr 3rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. void RotateBullet(Vector2 to)
  2. {
  3. Vector2 pos = bullet.transform.localPosition.normalized;
  4. float angle = Mathf.Atan2(pos.y - to.y, pos.x - to.x);
  5. Debug.Log($" position: {pos} direction: {to} angle: {angle}");
  6. float x = pos.x+ Mathf.Cos(angle) * radius;
  7. float y = pos.y + Mathf.Sin(angle) * radius;
  8.  
  9. var desired = new Vector2(x, y);
  10. bullet.transform.localPosition = desired;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement