Aligning a Compass with Sun Position Calculator in Unreal Engine?

Hey everyone,

I’m working on a compass for real-world architectural projects in Unreal Engine, and I need to set it up a so it points to true north based on the Sun Position Calculator plugin.

This is a really basic compass setup:

I’m struggling to correctly calculate the true north offset using the sun’s azimuth at solar noon. or if there’s a better way to do this? Is my approach correct?

My goal is when we add the sun position calculator to our levels.
fill in the latitude, longitude and timezone is to have a compass on the UI with the correct directions

Any help or suggestions would be greatly appreciated! Thanks in advance!

Hey @YahiyaJasem

when you place the SunPositionCalculator inside your map the default north position is along the x axis. With the NorthOffset you tell it where the real north is in this level because the program does not know how your level is rotated. This value can then be used for your compass.

Do you have reference points inside your map? e.g. points with known longitude and latitude values? Then you could calculate the bearing of two points.

Thanks for the explanation! I’m still a bit confused, though. I thought that by setting the latitude and longitude, the north direction would automatically align with the real-world north.

From what you’re saying, it sounds like the Sun Position Calculator assumes north is along the X-axis by default, and the North Offset is needed to correct that based on how the level is rotated—am I understanding that right?

I don’t currently have reference points with known latitude and longitude inside my map. If I were to add them, how would I calculate the bearing to determine the correct North Offset?

I really appreciate the help!

Hey @YahiyaJasem

here is an example which shows how to calculate the real north offset using this formula:

θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )

You calculate 2 bearings. One from the real world coordinates and one from the current in level coordinates to translate the editor coordinate system to the real world coordinate sytem. Both values will be added as the offset.

Go to SunPosition => Blueprints, right click EBP_GetNorthOffset and select Run.
UE50_SunPosition.zip (1.7 MB)

2 Likes

I can’t thank you enough! I’ll dive deeper into this, and implement it with my system.
much much appreciated!