hi all,
ive got a camera gimbal - one object moving on the y axis, and another object with camera (attached by hinge) moving in the x axis, creating a camera ‘gimbal’, which i move with add torque to their respective rigid bodies for a realistic movement, which works perfectly. i also have a mini map, with a top and a side view (this is a space game in a galaxy so top and side view provide 3d context of location and rotation in space). each of the top and side views in the mini map have a pointer that reflects the location and rotation of the camera location:
here is a code snippet i use to get the top view pointer to match the rotation of the camera gimbal on the cameras y axis, which translates to the pointers (UI) z axis, which works perfectly:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class getlocation : MonoBehaviour
{
RectTransform topmap;
galaxy2 galaxy2;
GameObject camerasphere;
RectTransform rt;
float scale;
void Start()
{
rt = GetComponent<RectTransform>();
topmap = GameObject.Find("blank for galaxytop").GetComponent<RectTransform>();
galaxy2 = transform.root.GetComponentInChildren<galaxy2>();
camerasphere = GameObject.Find("camerasphere");
scale = topmap.rect.width / (galaxy2.maxx+galaxy2.maxz);
}
void Update()
{
Vector3 currentpos = new Vector3(camerasphere.transform.localPosition.x*scale, camerasphere.transform.localPosition.z*scale,0);
rt.localPosition = currentpos;
Vector3 temprotation = new Vector3(rt.eulerAngles.x,rt.eulerAngles.y,-camerasphere.transform. eulerAngles.y);
rt.localRotation = Quaternion.Euler( temprotation);
}
}
the problem arises, however, when i use a similar (near identical) code to get the camera gimbals x axis to translate into the side map views pointers z axis. the pointer doesnt follow the cameras x axis all the way round but only bouces between 180 degrees = 90 + and 90 -. it wont go 360 degrees round, which doesnt make any sense because the same basic code works perfectly from the camera y axis to the pointers z axis. here is the code to get the rotation (and location) of the camera x axis:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class setlocation2 : MonoBehaviour
{
galaxy2 galaxy2;
GameObject camerasphere;
GameObject csg;
RectTransform rt;
RectTransform sidemap;
float scale;
void Start()
{
galaxy2 = transform.root.GetComponentInChildren<galaxy2>();
camerasphere = GameObject.Find("camerasphere");
csg = GameObject.Find("cameraspheregalaxy");
rt = GetComponent<RectTransform>();
sidemap = GameObject.Find("blank for galaxyside").GetComponent<RectTransform>();
scale = sidemap.rect.width / (galaxy2.maxx+galaxy2.maxz);
}
// Update is called once per frame
void Update()
{
Vector3 currentpos = new Vector3(camerasphere.transform.localPosition.z*scale,camerasphere.transform.localPosition.y*scale,0);
rt.localPosition = currentpos;
Vector3 temprotation = new Vector3(0,0,csg.transform. eulerAngles.x);
rt.localRotation = Quaternion.Euler( temprotation);
}
}
can anyone help please!?!! I am missing something or could this be a bug?
any help appreciated
many thanks
paul.