Page 1 of 1

RevoluteJoint stretching

Posted: Sun Aug 07, 2011 1:56 am
by Chaosed0
I have two different, but probably related, problems. Basically, I'm trying to replicate the system used in the game "Hammerfight," where you have weapons spin around a central axis (your ship).
The first problem is that when I create a "chain" of sorts out of rectangles and revolutejoints, and then I spin this system around, the chain links start stretching out. I would like them to stay connected to each other, end to end. The problem becomes more pronounced the more links there are in the chain.
The second is that when I create a rod attached to the "ship," and then I collide the rod into a wall, not only does it go through the ship, but when I stop forcing the rod down it acts like a pogo stick, propelling the ship. When the rod hits the wall, the system of the ship and the rod should simply stop.
Hopefully you can help! Two love files are attached, demonstrating the two problems. To move the "ship," the circle, click and hold the left mouse button. To see the chain stretching problem, click and hold the LMB and move it around in a circle, around the ship. To see the rod problem, collide the end of the rod into a wall.

Re: RevoluteJoint stretching

Posted: Mon Aug 08, 2011 12:56 pm
by Rad3k
Hi there.
I tried running your demos, but I was getting an error message
love: modules/physics/box2d/Source/Collision/Shapes/b2PolygonShape.cpp:224: b2PolygonShape::b2PolygonShape(const b2ShapeDef*): Assertion `d.x >= 0.0f' failed.
I think I know what's your problem though, as I have encountered the behaviour you describe. I haven't tried it myself, but I think that running the physics simulation more often and with smaller time step may help. Let's say, on each frame, instead of doing just

Code: Select all

world:update(dt)
do something like

Code: Select all

for i = 1, 4 do world:update(dt/4) end
This way the physics engine will have smaller errors to correct each time the update is done. It will probably cost you more cpu cycles each frame, but should improve the accuracy of simulation.
I don't guarantee it will work, but it's certainly worth a shot. If you try this, let me know if it worked.

Funny thing - I also tried to make a game like Hammerfight, but that was before I knew that Hammerfight exists :)

Re: RevoluteJoint stretching

Posted: Mon Aug 08, 2011 2:24 pm
by tentus
Rad3k wrote:Hi there.
I think I know what's your problem though, as I have encountered the behaviour you describe. I haven't tried it myself, but I think that running the physics simulation more often and with smaller time step may help. Let's say, on each frame, instead of doing just

Code: Select all

world:update(dt)
do something like

Code: Select all

for i = 1, 4 do world:update(dt/4) end
Don't do this, it won't help.

I was able to replicate your problem, though it wasn't terribly visible. Try cleaning up your code a little and maybe you'll spot the error. You've got some conflicting comments and such ("gravity will be 80" when it is 50). Also, is it just me or does the chain tend to "knot"?