Rotate 2D Image for Map like 3D player rotation

Hello,

on my 2D map I have an arrow Image.
Now I want to rotate it “flat” of Course on the map like the player’s look direction (Y-Axis?)

playerTexture.transform.localRotation=newQuaternion(0,Globals.PlayerTransform.localRotation.y,0,1);

playerTexture is the 2D Icon, Globals.PlayerTransform the 3D Player.

Somehow it does not rotate like it should, any help please?

Thanks :slight_smile:

Okay, it gets better when I rotate the 2D Image only the Z axxis

playerTexture.transform.localRotation=newQuaternion(0,0,Globals.PlayerTransform.localRotation.y,1);

But still it does not rotate like it should, and only a Little bit?

Is there some multiplicator or math formula I Need to convert 3D Rotation of Y axxis into 2D Rotation value?

Hello,

still got no clue. Any idea, how I can rotate my 2D arrow Image on my 2D map into the direction the 3D Player (only Y axxis?), standing on the ground is facing?

Thanks and happy new year!

Maybe an screenshot/image would help… is that like a minimap for player?

Yes the Player is a human running around on the ground in 3D.
He can have a look on a 2D map. Then there is an 2D arrow (loaded as UI Image) on the map.

The question is how can I 2D rotate the flat Image arrow on the 2D map so it has the same angle like the 3D Player.


See the black arrow in the middle.

playerTexture.transform.localRotation=newQuaternion(0,0,Globals.PlayerTransform.localRotation.yMathf.PI2f,1);
(this is not really working, but it is better than before)

playerTexture is 2D UI Image, Globals.PlayerTransform is transform of 3D Player.

Thanks for helping!

something like this seemed to work for me, probably some easier way to do it though…

    public Transform player;
    public RectTransform arrow;

    void LateUpdate()
    {
        var newRot = player.eulerAngles;
        newRot.x = 0;
        newRot.z = 360 - newRot.y;
        newRot.y = 0;
        arrow.rotation = Quaternion.Euler(newRot);
    }
2 Likes

That’s perfect! Thanks a lot mgear :slight_smile: