I’m completely lost on quaternion math and applying rotations so here is my question.

How can I get the rotation of object 1, calculate from that a target angle, and then apply that rotation to object 2 ?

here’s what I came up with so far :

```
public var thePlayer : Transform;
var speed : float = 8.0;
var turnSpeed : float = 0.5;
var startRotY : float = 25.0;
enum allStates { Idle, Spawning, FlyingForward, TurningToBehind, WaitingToRespawn }
var currentState : allStates;
function Spawning()
{
// position at relation to player + randomness
transform.position = thePlayer.position + ( thePlayer.forward * -10.0 ) + ( thePlayer.right * -20.0 );
// rotation at angle to player + randomness
var customRotation : Quaternion = Quaternion.Euler( thePlayer.rotation.x, RoundAngle( thePlayer.rotation.y + startRotY ), thePlayer.rotation.z );
//this.transform.rotation = thePlayer.rotation;
transform.rotation = customRotation;
// Switch state
currentState = allStates.FlyingForward;
}
function TurningToBehind()
{
// rotate to 180' to player
var turnAngle : Quaternion = Quaternion.Euler( thePlayer.rotation.x,
RoundAngle( thePlayer.rotation.y - 180.0 ),
thePlayer.rotation.z );
transform.rotation = Quaternion.Lerp( transform.rotation, turnAngle, turnSpeed * Time.deltaTime );
// keep turning and flying
transform.position += transform.forward * speed * Time.deltaTime;
//check if position is behind players local Z
// using Dot.Product here =]
// if behind player , change state
//currentState = allStates.WaitingToRespawn;
}
function RoundAngle( theAngle : float ) : float
{
if ( theAngle > 360 )
{
theAngle -= 360;
}
else if ( theAngle < -360 )
{
theAngle += 360;
}
return theAngle;
}
```

When I rotate the Player, the Enemy does not notice this or use anything but Euler(0,0,0) while using thePlayer.rotation in any rotation calculation.