Controlling an objects angle and radius from a given point.

Topics: User Forum
Jul 22, 2009 at 7:31 PM

I've tried my hardest to achieve a particular constraint with various configurations of the standard joints and springs, but it's proving rather difficult. So, any help is appreciated, the constraints are as follows:

Currently I have two bodies--collision does not occur between the two. Assume that body A is static. Body B needs to be able to rotate around body A at varying lengths.

However, there are a few catches:

Object B must always try to point towards object A.

It must be possible to supply a set distance from body A to body B (Presumably through setting the max/min of a slider joint).

And it must be possible to supply a target angle for the direction from body A to body B.


If further clarifaction is in order, simply ask.

Jul 22, 2009 at 8:04 PM

You figured out the slider joint by yourself. Simply attach the center of each of the bodies to the slider joint and they will always be at a fixed distance (within a min/max value) from each other.

As for the pointing towards each other, you will have to do some trigonometry. The best sample of doing homing missiles, spotlights and the like is the one found on XNA Creators Club.

But it really depends on your game. If you have two rods that should point at each other at all times, then they simply share the same angle (rotation value).

Jul 22, 2009 at 8:31 PM

I'm affraid you misunderstood my question.

As for always pointing towards, I already have a trig function doing that.

The only reason I supplied those two things is incase they interfered with the third constraint...

That being... object B rotating around (ie. Orbitting) object A at a set angle. Not to be confused with the actualy rotation of the body itself.

Jul 22, 2009 at 9:14 PM
Edited Jul 22, 2009 at 9:21 PM

Are you able to draw a small illustration if this?

Edit: Updated text to sound a little less rude :) It was not on purpose.

Jul 22, 2009 at 9:26 PM

Simple illustration? Here you go:


The bigger circle is object A, the smaller circle object B.

The red dots are the respective origins.

The blue line is a target distance.

The red angle marker is a target angle.

Jul 22, 2009 at 9:35 PM

You could perhaps attach a body between the two objects, but an angle joint on the body and attach the two objects to the body by revolute joints.

Jul 22, 2009 at 9:42 PM

I figured that would be a way to do it, but I seem to signifigantly lose performance with the extra object there... Any way to optimize?

Jul 22, 2009 at 10:16 PM

Adding one extra body should not have a big impact on performance. A couple of extra joints should not either. Are you able to insert the PhysicsSimulatorView from the Farseer Physics Engine samples into your project?

It will show you the time it takes to update each part of the engine. If something takes a lot of time it should show op.

Jul 22, 2009 at 10:27 PM

Well, I suppose I wasn't clear, this particular type of joint is used en masse.

It's not like adding one extra object as much as it is adding ... a lot of extra objects. :P

Nevertheless, I suppose it will have to do.

Jul 22, 2009 at 10:29 PM

The joints themselves and bodies are as optimized as they come. You will have to look at other options. There are a lot of ways to optimize and if you need any help with it, feel free to ask on the forums.

Jul 22, 2009 at 10:36 PM

Thanks for the help. :]