- Home /
Question by
murkertrer · Jun 06, 2016 at 04:45 PM ·
vector3quaternioneuleranglesoffsetradar
Rotate some coordinates in relation to an object's rotation
Hi guys,
So I'm stuck with this one. I don't have a deep knowledge of quaternions or anything of the sort, maybe someone who does might be able to help me.
I'm trying to get a 3d radar working. So for this, I make dummy objects, that are possitioned in the balldummy, relative to how the real objects are position in relation to the player. So far, this code works. If I turn, The objects change respectiveley
void ModifyPos()
{
if (radarObjects.Count > 0) {
for (int i = 0; i < radarObjects.Count; i++) {
if (radarObjectsOriginals [i]) {
float distance = Vector3.Distance (this.transform.position, radarObjectsOriginals [i].transform.position);
float percentage = (radius - (radius - distance)) / radius;
if (externalDisplayRadar) {
radarObjects [i].SetActive (true);
float distanceToWorkWith = radarDummyBounds;
float relativeDistance = distanceToWorkWith *percentage;
Vector3 relativePos = ball.transform.position - radarObjectsOriginals [i].transform.position;
Quaternion rotation = Quaternion.LookRotation (relativePos);
Vector3 negDistance = new Vector3 (0.0f, 0.0f, -relativeDistance );
Vector3 position = rotation * negDistance + ballDummy.transform.position;
radarObjects [i].transform.position = position;
}
}
}
}
}
However, I want the objects to also change in relation to the radars rotation (additionally that of the player).
I tried adding
rotation = ballDummy.transform.rotation * rotation;
after
Quaternion rotation = Quaternion.LookRotation (relativePos);
which makes the objects change in relation to the radars orientation, but they no longer change in relation to the player...
how can I reconcile this two behaviours? Any thoughts much appreciated.
sin-titulo.png
(367.3 kB)
71603-sin-titulosasdsadsda.png
(326.7 kB)
Comment