- Home /
The question is answered, right answer was accepted
Minimap rotating nodes
Hey there !
I'm working on a minimap system and I'm stuck at a point. My minimap is working fine, but I'd like to improve it by rotating the nodes, which are displayed on the map.
Here's what I've done so far.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MiniMap : MonoBehaviour {
public Texture building, arrow;
private Rect buildingRect;
private GameObject[] objects;
private GameObject player;
// Use this for initialization
void Start () {
objects = GameObject.FindGameObjectsWithTag("Objects On Map");
player = GameObject.Find ("Player");
}
void OnGUI () {
foreach (var obj in objects) {
if (Vector3.Distance(obj.transform.position, player.transform.position) < 100) {
buildingRect = new Rect((100 + (obj.transform.position.z - player.transform.position.z )),300 + ( obj.transform.position.x - player.transform.position.x ) , 10,10);
GUI.DrawTexture(buildingRect, building);
}
}
GUI.DrawTexture(new Rect(100, 300, 10,10),arrow);
}
}
For now I'm displaying all nodes from a for each cycle, and it's only for testing purposes. I was playing around with either adding or subtracting the eulerangles.y from the displayed nodes X and Z coordinates but hence I don't know that much about that part of math, I'm asking for your help.
I think I'm on the right way to go, but would need a push to continue developing my system. Thanks in advance !
Personally I would not do this in OnGUI - that fuction is called many times per frame and you are doing some stuff in it that I'd try to avoid. Is your $$anonymous$$imap the oft seen 2nd camera, orthographic style? You could place something above objects you want to see on the $$anonymous$$imap and use the camera culling mask so they show up (and don't in normal view).
As I already pointed it out, this is only for testing purposes. And we aren't talking about any cameras, that's something I'd like to avoid. Basically I'm using my gameobjects coordinates to make a 2d projection from it. $$anonymous$$y only issue is the math behind changing the position of the X,Z coordinates either adding/subtracting to create the illusion of the map rotating.
I think that's what I was looking for !
I'm gonna test it out later, then reply to you if it works ! :)
Answer by Scribe · Sep 01, 2015 at 03:42 PM
You need to decide on some central point (which you rotate around), then this function can rotate around that point (hopefully! untested...):
Vector3 RotatePoint(Vector3 point, Vector3 centre, Vector3 axis, float angle){
Vector3 offset = point - centre;
Quaternion q = Quaternion.AngleAxis(angle, axis);
Vector3 newPos = centre + (q*offset);
return newPos;
}
and so you could call it as:
Vector3 newPoint = RotatePoint(currentPoint, Vector3.zero, Vector3.up, 30f);
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Limit Rotation Issues 1 Answer
Am I missing something when it comes to basic math? 1 Answer