Initial Question:
I'm trying to create a minimap for my game in Unity. It consists of a 2D image sprite within a mask. I've got the rotation and the movement within the mask down, but the only problem is the fact that the image rotates around its central point, instead of the central point of the mask, which is where the player is. Is there any way to fix this in code or using parenting or something? Any help is appreciated.
Code for the image:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIMinimap : MonoBehaviour
{
public Image minimap;
public Transform border;
private float xOffset;
private float yOffset;
// getting values from the player van
public CarController van;
private float yRotation;
private Vector3 eulerRotation;
private Quaternion rotation;
private float yMovement;
private float xMovement;
public Vector3 Movement;
void Start()
{
// getting offset which changes with screen size
xOffset = transform.position.x;
yOffset = transform.position.y;
}
void Update()
{
// Getting Y rotation of the van (direction facing)
yRotation = van.vanRotation.eulerAngles.y;
// turning that into a vector for rotation of plane (in Z as rotation of map is on a different plane to van)
eulerRotation = new Vector3(0, 0, yRotation);
// converting euler angles into quaternion
rotation.eulerAngles = eulerRotation;
transform.rotation = rotation ;
// converting the position of the van on the real map to movement of the image, 0.247... is the scale of the image, while x and
// y offset account for screensize
yMovement= (-van.transform.position.x * (float)0.24721213) + (float) + yOffset;
xMovement = (-van.transform.position.z * (float)0.24721213) + (float) + xOffset;
Movement = new Vector3(xMovement, yMovement, 0);
transform.position = Movement;
}
}