Page 1 of 1

Revolute Joints that move

Posted: Tue Feb 23, 2010 12:36 am
by kikito
Hi there!

I'm experimenting for the first time with joints (yes I'm aware of how wrong that sounds)

At this moment I'd like to "attach" two bodies together with a Revolute Joint.

At the moment I have the following:

Code: Select all

  -- x, y, body1 and body2 already defined
  local joint = love.physics.newRevoluteJoint( body1, body2, x, y )
  joint:setCollideConnected(false)
The problem I'm having is that this joint "fixes" body1 and body2 into space. They can "revolute" around x,y. But they can't "traslate" much, since x and y seem "fixed".

Body1 and body 2 look like butterflies pinned on the wall.

In my case body1 is a tank and body2 is the tank's turret. They are not of much use if the tank can't move!

Ideally, I'd like to apply forces to body1 so that body2 "follows it around", while still being able to orientate itself.

So, that's my question - how do I make the joint "not fixed"?

Re: Revolute Joints that move

Posted: Tue Feb 23, 2010 3:44 am
by Fourex
It would probably be much easier to do it yourself, rather than use the physics. For something this simple, it would be a lot less effort. Just use two variables to keep track of directions. I'll use 'bodydeg' and 'turretdeg'. bodydeg changes when rotating the body, and turretdeg changes when rotating the turret. But, when drawing the turret, don't just use turretdeg; use turretdeg+bodydeg, so that when you are rotating the body, the turret moves with it, but you can also rotate the turret individually. I bet you wouldn't have any trouble translating my jumble of gibberish into some code. I'm not really sure, but I'm pretty sure that's what you want. If this isn't what you are trying to do, then ignore me. :oops:

Re: Revolute Joints that move

Posted: Tue Feb 23, 2010 7:01 am
by Robin
Joints are rather freakish. You must be very brave to venture there. However, I think you will not succeed. Go by what Fourex said. ;)

Re: Revolute Joints that move

Posted: Tue Feb 23, 2010 8:11 am
by kikito
:( I'm a bit sad because of this.

I already had some code that adjusted the turret position and angle on each "update" call, but it doesn't "scale" too well - forces aren't transmitted with these joints.

Imagine that instead of a turret it was an orientable propulsor. It would be so clean if I could just apply a force to the propulsor and it was translated to the hull via the joint...

But ok, I got it, I can't use a revolutejoint for this. I'll try with a distancejoint then (with distance 0). And if that fails, code the thing myself.

Thanks and regards!

Re: Revolute Joints that move

Posted: Tue Feb 23, 2010 11:43 pm
by kikito
Hmm. No luck with distancejoints. My tank was dancing like crazy around its turret, no idea why.

I'll have to continue using my suboptimal solution then.

Re: Revolute Joints that move

Posted: Tue Feb 23, 2010 11:52 pm
by bartbes
Quote from the issue tracker:
bartbes wrote: Straight from the Box2D manual
Box2D Manual wrote:A revolute joint forces two bodies to share a common anchor point, often called a hinge point. The revolute joint has a single degree of freedom: the relative rotation of the two bodies. This is called the joint angle.

Re: Revolute Joints that move

Posted: Wed Feb 24, 2010 1:21 am
by kikito
I Bartbes,

I believe you are not interpreting the documentation correctly on this case. It says that there's a shared point between the objects, yes. However it never says "the joint point is fixed in space".

There are lots of people out there doing 2d cars using revolutejoints as motors in their wheels. Besides, it makes sense, too - who would want to make a 2d engine without 2d cars? That would be like, the first thing one would try to do :D.

Two (flash) examples can be seen here and here (truck car game).

In my limited knowledge, I've browsed the source code and could not find any obvious problem on the LÖVE implementation - it is a fairly straightforward "façade" to the box2d object. Maybe the box2d lib used is outdated?

Re: Revolute Joints that move

Posted: Wed Feb 24, 2010 2:20 pm
by kikito
I was confused - once again!

The problem was in my code, not on LÖVE.

It is completely possible to make revolutejoints that move around.

The one thing you must not forget is to give mass to both bodies! Otherwise they will be "anchored" to the background.

Once I set the mass of my turret to 100 grams turret my tank was happily moving around.

Apologies to anyone that has spent any time reviewing this. I hope at least this forum post helps anyone encountering the same issue in the future.

Re: Revolute Joints that move

Posted: Sat May 08, 2010 8:07 pm
by Fruchthieb
Yes, it helped me, but not enough.

in order to create the joint, you have to specify mysterious "x" and "y". What for coordinates are they? Local coordinates? Of which body? Global Coordinates? And if global, how to move the joint?

Fruchthieb...

Re: Revolute Joints that move

Posted: Sun May 09, 2010 11:47 am
by kikito
Fruchthieb wrote:Yes, it helped me, but not enough.

in order to create the joint, you have to specify mysterious "x" and "y". What for coordinates are they? Local coordinates? Of which body? Global Coordinates? And if global, how to move the joint?

Fruchthieb...
Hi Fruchthieb,

The coordinates are in World space (global, as you call them).

Specifying them in global coordinates doesn't imply that they are fixed - once it is created, it will move along with the bodies (provided that both of them can be move)

If you can transform local coordinates into world coordinates using Body:getWorldPoint