Getting a configurable joint to point at another object

Hi all,

I’ve been working on a project with joints, and I’ve hit an issue with configurable joints that I can’t wrap my head around. Say I have two objects:

Object A

  • Has a configurable joint
  • Rotation controlled by physics
  • Should always “look at” object B (unless prevented by other colliders)

Object B

  • The “target”
  • Can arbitrarily move around the scene

Basically I’d like Object A to be a physics-controlled object that always rotates to “look at” Object B.

I’ve been attempting this by setting the TargetRotation property of Object A to a Quaternion that looks at Object B. This causes Object A to rotate as Object B moves around the screen, but its rotation is not correct. Object A’s rotation does not seem to follow or point at Object B in any useful way.

Here are the non-default properties of my joint:

  • X/Y/Z Motion: Locked
  • Angular X/Y/Z Motion: Free
  • Target Rotation: Set by a script
  • Rotation Drive Mode: Slerp
  • Slerp Drive: Position only (other values set to 1)

I guess I don’t fully understand how the TargetRotation property works. I’m at a loss on how to fix this.

Thanks for reading.

I figured it out!

Originally I was getting a vector pointing towards the Target from the joint and using Quaternion.LookRotation(). I needed to also invert the Quaternion (using Quaternion.Inverse) before setting it as the joint’s TargetRotation.

It works great now.

Thanks this really helped :slight_smile: