Help with rotations and angles

I don’t even know is this thing I’m trying to achieve has a name, but here goes.

I’m building a minimap with a second orthographic camera looking downwards. This camera follows the target by taking his X and Z position. That’s easy.
My problem starts when I try to make that camera rotate with the target, so the ‘north’ of the minimap is aligned with the target’s forward direction.

I used this

theCamera.rotation = Quaternion.Euler(90,target.eulerAngles.y,0);

and it works fine on flat ground, but when the target walks a slope, the minimap suddenly rotates, and goes back to normal when in flat ground again. Like so:


I guess this happens because the angle of the target gets modified as the forward direction goes up, but I can’t figure out how to solve it!

Is there any way I could get the global Y angle of the target?

It is always dangerous to read eulerAngles and expect them to be any particular value. There are multiple Euler angle representations for any physical rotation. If you set the rotation to (180,0,0), you might immediately read eulerAngles and get (0,180,180) instead. Here is an alternate solution that I think will work:

angle = Mathf.Atan2(target.right.z, target.right.x) * Mathf.Rad2Deg;
theCamera.rotation = Quaternion.Euler(90, angle, 0);

If you have problems with this solution, there are other ways to approach the problem.

Hi robertbu,

This is not a direct solution to your problem but maybe you want to take a look at the popular KGFMapSystem?

It took us nearly a year to develop this system and we have solved all possible minimap problems out there. For example we are not using a second ortographic camera cause this will reduce your game performance by 2.Instead we are taking an orthogonal photo of your scene and render it instead.

The system is very easy to use, not very expensive, fully customizeable and I’m sure it will save you a lot of headache.

You can also checkout the documentation here:

If you have any questions you can contact me any time on

Best wishes,