Trying to create a chain/rope using pin joints in Chipmunk

Moderator
Posts: 698
Joined: 2002.04
Post: #1
As the title says, I'm trying to create a chain/rope using pin joints in Chipmunk - the top of the chain is attached to a flying enemy entity whilst from the bottom of the chain dangles another enemy entity - neither enemy entity is part of Chipmunk's simulation, rather the top enemy updates the top link in the chain's position using cpBodySlew(), and the bottom enemy takes its position from cpBody->p attribute of the bottom link in the chain - easy enough.

Except that the chain loses energy far, far too slowly (occasionally causing the bottom enemy entity to orbit the top Blush) - so, I'm just wondering what attributes I should be tweaking (or functions overriding Annoyed) to tweak the speed at which the chain loses energy?

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
I would not use Chipmunk to do this at all:
http://www.idevgames.com/forums/thread-8...l#pid69303

Doing that you can get a better looking chain with much lower CPU usage.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 698
Joined: 2002.04
Post: #3
Thanks for the reply Skorche! CPU usage isn't really an issue - the game isn't using Chipmunk for its physics/collisions except for a few FX... and whilst a "don't do that" from the developer of the library would usually discourage me from "doing that", I'm going to first try an approach where the links in the chain have attached an inverted 'V' collision shape, which should at least limit the swing and so stop the bottom enemy entity orbiting the top...

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
Well in that case, I'd recommend using slide joints instead of pin joints. Using pin joints will make the chain look like it's made out of a bunch of solid segments that are riveted together. You can also set some damping cpSpace.damping on the space to add a bit of drag to the chain. The value is a percentage of velocity per second. A value of 0.3 means that without external forces an object will be moving 30% of it's speed each second.

You should still look into the paper I linked in that other post though. Even beyond the CPU usage, it will probably be easier to get a nice, stable, animated chain.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 698
Joined: 2002.04
Post: #5
(Feb 11, 2011 03:04 PM)Skorche Wrote:  Well in that case, I'd recommend using slide joints instead of pin joints. Using pin joints will make the chain look like it's made out of a bunch of solid segments that are riveted together.

I looked into using cpSlideJoint (as well as using cpDampedSpring) earlier, but both seemed to make the chains even less chain-like Annoyed

(Feb 11, 2011 03:04 PM)Skorche Wrote:  You should still look into the paper I linked in that other post though.

Oh, I haven't discarded that suggestion - I'll likely look into it even if I end up using Chipmunk for the chains Smile

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Post Reply