Direction arrow that rotates around player

I’m trying to make a navigation arrow in my top down 2d game, similar to how it works in gta 1/2:

I’ve got the arrow currently working so it points towards it’s target. ‘arrow’ is the nav arrow object and ‘target’ is where it points at. My code:

var relPos = target.position - arrow.transform.position;
var ang = Mathf.Atan2(relPos.y, relPos.x) * Mathf.Rad2Deg;
var rotation = Quaternion.AngleAxis(ang, Vector3.forward);
arrow.transform.rotation = rotation;

But at the moment it just sits next to the player and rotates. I can’t figure out the technique or maths I need to make the nav arrow circle around the player as well as point in direction of target.

Any hints for me to get the ball rolling?

there is a very handy function called “RotateAround”

1 Like

You could also add the visual component of your arrow to a child GameObject and offset it there, then just rotate the parent GameObject as you’re doing now.

So your hierarchy would look like:

Player
   Arrow Container
      Arrow Graphic (x: 5, y: 0, z: 0)

Then rotate the arrow container and it will maintain its 5 unit offset.

1 Like

I’ve not been able to get these to work yet. I did look at rotatearound before, but doesn’t that do a continual orbit around? I need it to only position in the direction of the target.

Will keep at it…

Did you try what @GroZZleR suggested? There is no complex math needed: add LookAt to “Arrow Container”.

er… no. It can be used for that but only if you continuously call the function… it’s essentially the same as Rotate, just with a given origin to rotate around rather than the transform’s origin