- Home /
How to adjust rotation of map icon with a gameObject.transform.rotation
So I've been programming a space shooter game and I've been trying to make a crude map to help with orientation. I wanted to make sure the rotation of my spaceship is reflected by the icon of the map (some sort of arrow). I'm currently doing this by feeding the rotation of the spaceship into the rotation of the map icon.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapPlayerShip : MapObject
{
private void Awake()
{
ToggleLabel(false);
RectTransform = GetComponent<RectTransform>();
}
public override void UpdateMapObject()
{
base.UpdateMapObject();
RectTransform.rotation = mapController.TransformPlayerShip.rotation;
}
}
This actually works, but my map has the world z coordinate for an y coordinate, so the rotation of my map Icon doesn't really reflect what's going on in the real game world.
Basically my worldspace has x,y,z coordinates, while my map has x,z,y coordinates. How can I adjust the rotation so it's actually correctly displayed by the icon? Furthermore is there some way to stop it from showing the rotation into the otherwise invisible depth? (So it's basically only rotating around the z axis?)
Your answer
![](https://koobas.hobune.stream/wayback/20220613014835im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why Is Rotation Different For RectTransform? 0 Answers
Trying to rotate a 2D image over time to a specific angle, but it's rotating its Y value every time 1 Answer
Object rotation in code is different than it is in game? 1 Answer
Rotate rect transform ui by touch 0 Answers
Calculate rotation angle for two side of cube ( like dice ) from Quaternion.identity 0 Answers