Hello.
I spent many hours trying to wrap my head around what appears to be a simple problem, but am hindered by lack of knowledge about quaternions. I haven’t found past answer that explains my question.
This is the scenario:
-There is an object A1 and another object B1, and they can be at any position in space.
-I need to get values about B1’s position and rotation relative to A1
-After this calculation is done, two new objects are created A2 and B2, and position and rotation of B2 relative to A2 should replicate the state we had with A1 and B1, but considering that A2’s rotation and position relative to world space is not the same as A1.
-How do I get position and rotation of B2, relative to whatever position and rotation of A2 is?
So, if A1 is pointing north, and B1’s direction happens to be 60 degrees from A1.up, and 10 degrees from A1.forward, at distance of lets say 10 units, how do I replicate this exact B1 relative to A1 position and angle for B2, if A2 is pointing lets say east.
Also, A2 and B2 are scaled different than A1 and B1, but I guess that is as simple as multiplying the values by scale factor, what I am curious about most is how to get B2 position.
//to help make answers more clear you could use this code as base
var A1pos : Vector3 = A1.transform.position,
B1pos : Vector3 = B1.transform.position
A1rot : Quaternion = A1.transform.rotation,
B1rot : Quaternion = B1.tranform.rotation;
var thevalue : Vector3 = GetPositionRelativeToPosition (A1pos, B2pos); //how to get this value(s) and apply properly?
var A2 : GameObject = InstantiateA1(),
B2 : GameObject = InstantiateB2(),
scaleFactor = 10.0;
B2.transform.position = ReplicateRelativePosition(A2, thevalue, scaleFactor); //or ReplicateRelativePosition(A2, A1Pos, B2pos, scaleFactor) would be fine as well
B2.transform.rotation = ReplicateRelativeRotation(A2, A1rot, B1rot) ;
// Please help me write these functions.
// GetPositionRelativeToPosition (
// ReplicateRelativePosition(
// ReplicateRelativeRotation(
Thanks!