Compass Math Relative to Player and Camera

Hi all,

I am making a shooter game and have been trying to make compass-like UI elements for a variety of purposes, like indicating what direction the player takes damage from, or in what direction round objectives (such as flags) are located relative to the player.

Since I wasn’t sure where to start, I found this free model in the toolbox whose functionality is vaguely similar to what I’m going for. I intend to design my own version from scratch, but I will use this for now until I have a better understanding of the math behind it.

Currently, it always points north, and I am trying to adjust it so that it points towards the red block; so if it were working correctly in this image, the arrow would be pointing to the left. I have figured out how to make the arrow’s position change based on my character’s position relative to the red block, and I have figured out how to make it change based on the direction my camera is facing, but I cannot seem to make it change based on both values at once (while still being fully accurate).

Shown here is the math that came with the free model. How can I change it so that no matter where the player is, and no matter where their camera is facing, the arrow always points toward a designated object?

Any guidance is greatly appreciated.

1 Like

Found this, I think you should try it.

Took a fair amount of modification, but this worked, thank you!