Revolute Joints that move

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Revolute Joints that move

Post 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"?
When I write def I mean function.
User avatar
Fourex
Citizen
Posts: 53
Joined: Tue Nov 10, 2009 2:33 am
Location: Earth

Re: Revolute Joints that move

Post 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:
Last edited by Fourex on Tue Feb 23, 2010 7:35 am, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Revolute Joints that move

Post 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. ;)
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Revolute Joints that move

Post 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!
When I write def I mean function.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Revolute Joints that move

Post 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.
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Revolute Joints that move

Post 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.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Revolute Joints that move

Post 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?
When I write def I mean function.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Revolute Joints that move

Post 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.
When I write def I mean function.
User avatar
Fruchthieb
Prole
Posts: 20
Joined: Sat Sep 26, 2009 12:04 pm
Location: austria

Re: Revolute Joints that move

Post 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...
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Revolute Joints that move

Post 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
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot], slime and 50 guests