1
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ what language are you using \$\endgroup\$ – user116458 Jun 16 '18 at 11:37
  • \$\begingroup\$ This might sound silly, but I get the feeling you've done a mistake somewhere and the empty objects do not move, when you think they are. Have you done anything to ensure that they move as expected? Like debugging it's position, or even just giving them a mesh so that you can see them while the game is running ? \$\endgroup\$ – TomTsagk Jul 19 '18 at 15:23
1
\$\begingroup\$

If the problem is that the position itself does not change, probably it is due to some mistake in assigning a value to rotationReference. Check that you do not change its value anywhere in the code. And it is "RotationReference = ReferencePoint" not the other way round and so on.

Also I don't see why you need referencePoint on object1 and not just use Object1 itself as the target. But maybe I just don't understand what you're trying to do.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your reply! The value is not mutated anywhere in code. The reason for using a referencePoint is complicated; but, long story short: The existing models that I have to work with (created in and imported from an external program) require some hacks for them to behave properly in the scene. \$\endgroup\$ – user112729 Apr 12 '18 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy