iDevGames Forums
Ball and chain - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Ball and chain (/thread-8572.html)



Ball and chain - markhula - Jan 23, 2011 05:47 AM

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


RE: Ball and chain - Applewood - Jan 23, 2011 06:31 AM

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)


RE: Ball and chain - markhula - Jan 23, 2011 06:38 AM

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


RE: Ball and chain - Skorche - Jan 23, 2011 10:57 AM

Use jakobsen style vertlet physics: http://www.gamasutra.com/resource_guide/20030121/jacobson_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.


RE: Ball and chain - markhula - Jan 23, 2011 11:02 AM

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


RE: Ball and chain - Skorche - Jan 23, 2011 05:39 PM

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.


RE: Ball and chain - markhula - Jan 24, 2011 02:19 AM

Ok!, though can't see any definitions for all the cpvlerp,cpvsub etc. etc. etc.

Cheers


RE: Ball and chain - Skorche - Jan 24, 2011 07:25 AM

Those are all part of the Chipmunk library. If you just want to look at the cpVect header: http://code.google.com/p/chipmunk-physics/source/browse/trunk/include/chipmunk/cpVect.h

You can grab the full lib from my signature.


RE: Ball and chain - markhula - Jan 24, 2011 07:28 AM

Thanks Skorche,

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

Cheers


RE: Ball and chain - haqu - Apr 18, 2011 10:39 PM

Skorche, thanks for posting example implementation. it's easier to understand how it works, when there is a code.