I have a parent game object Object1
. It has a child, which is simply an empty game object called ReferencePoint
. ReferencePoint
can be any arbitrary point on Object1
itself.
I have another game object Object2
. It has a public field called RotationReference
, of type Transform
. In the inspector, the ReferencePoint
on Object1
is assigned to the RotationReference
field on Object2
.
As Object1
moves, I expect ReferencePoint
to change its position as well. Object2
is supposed to change its rotation to face its RotationReference
-- in this case, the ReferencePoint
on Object1
:
public override void Rotate()
{
Vector3 relativeRotationReferencePosition =
this.RotationReference.position - this.transform.position;
this.transform.rotation = Quaternion.LookRotation(relativeRotationReferencePosition);
}
However, I noticed that Object2
is not rotating at all, even when Object1
is moving. When I step through the call stack multiple times, I discover that this.RotationReference.position
always has the same value, even though Object1
is moving.
What am I missing here?