Ball and chain

Member
Posts: 117
Joined: 2010.09
Post: #1
Hi all,

I'm not using a physics engine because I like 60fps and don't need many real world physics.
I would like to implement a simple chain effect.
i.e. pull 1 end and the rest follows appropriately.
I'm working in 2d so the effect is really just for visual 'niceness' rather than a requirement.
I have googled but can't seem to fine anything relevant to what I need - was hoping I would find some as3 code example; but of course they tend to use 3rd party physics engines.
Old school 2d tile games sometimes had these effects (zelda, castelvania etc.) so just wondering if anyone has any pointers or suggestions.

Cheers
Quote this message in a reply
Member
Posts: 54
Joined: 2010.10
Post: #2
A physics engine only takes a lot of CPU if you give it a lot of tasks to manage. Sounds like Box2D would solve your problem perfectly to me. I can't imagine it would be doing much more than any homebrew solution might entail.

(I can't think where a link might be for your rope problem as I solved it myself once a while back. I'm no math whizz either - it's not hard if you sit and think about it, especially in 2D. Read up on moments and torque)

Paul Johnson
Great Little War Game
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #3
Thanks Applewood.
The reason I don't use a physics engine is it wouldn't fir in with everything else I have :-)))
For example it's not going to integrate with my tile collision map and yet I would like my chain(rope) to register collisions with the scenery. I'd have to implement everything in the physics world to make all objects correct; and I don't want to do that! :-))))
Will check out moments and torque.

Cheers
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
Use jakobsen style vertlet physics: http://www.gamasutra.com/resource_guide/...n_01.shtml

I recently did a quick example implementation for Chipmunk/Cocos2D here including drawing thick lines using triangle strips: https://gist.github.com/792276

It would be very easy to extend to be textured.

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
Member
Posts: 117
Joined: 2010.09
Post: #5
Hey Skorche,

Thanks for the info. I'm an old style 'C' guy; but I'll take a bash at understanding the obj-c stuff and chipmunk.
Hmmm........

Cheers
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
Chipmunk is written in C, and the vertlet code I pasted does all the heavy work in C functions. Other than that it more or less just has an init, draw and step methods to fit into Cocos2D. I think you should find it quite understandable if you read the Gamasutra link. Wink

The Chipmunk parts aren't particulary important either. I just used it for the 2D vector functions and to get the rope endpoints from the rigid body objects that they connect to in the physics world. You can rip all of that out and just set the endpoints of the rope using whatever code you want.

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
Member
Posts: 117
Joined: 2010.09
Post: #7
Ok!, though can't see any definitions for all the cpvlerp,cpvsub etc. etc. etc.

Cheers
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
Those are all part of the Chipmunk library. If you just want to look at the cpVect header: http://code.google.com/p/chipmunk-physic...k/cpVect.h

You can grab the full lib from my signature.

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
Member
Posts: 117
Joined: 2010.09
Post: #9
Thanks Skorche,

I will take a look and see if I can work it out! ;-))

Cheers
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2011.04
Post: #10
Skorche, thanks for posting example implementation. it's easier to understand how it works, when there is a code.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Ball Bouncing in a circle strikerjax 6 4,937 Jul 6, 2009 02:39 PM
Last Post: strikerjax