x


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.

more ▼

asked Feb 15 '12 at 04:46 PM

VixOrien gravatar image

VixOrien
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Feb 16 '12 at 02:26 AM

VixOrien gravatar image

VixOrien
1 1 1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1865
x145
x102
x63
x3

asked: Feb 15 '12 at 04:46 PM

Seen: 812 times

Last Updated: Feb 16 '12 at 02:26 AM