Creating a rotating platform

Official forum for the Chipmunk2D Physics Library.
Post Reply
francisco
Posts: 1
Joined: Tue Sep 06, 2011 12:37 am
Contact:

Creating a rotating platform

Post by francisco »

Hi, I´m pretty new to the chipmunk engine and I´m struggling to get the following to work (In my mind it sounds like it should be simple but I can't get it to work): I want to have a platform, that is floating, and has a pivot point that limits its movement in a circular fashion, sort of:

http://www.2pstart.com/reviews/wariowar ... mario3.jpg

How could I achieve this in chipmunk?

I've tried using a pivot joint and disabling the gravity. That shows the platforms in place but the moment I apply an impulse on them, they are sent flying over. I would like them to stay in place but rotating.

Thanks in advance for any help!

Francisco
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Creating a rotating platform

Post by slembcke »

You have two choices to accomplish that. Using rogue bodies or animating constraints.

Rogue bodies: slightly more work, but with better results. Create an infinite mass body to attach the platform to but don't add it to the space. Add the collision shape normally. Instead update it's position and velocity each frame manually. When you update the velocity do this: cpvmult(cpvsub(newPosition, oldPosition), 1.0/dt) where dt is the same value you pass to cpSpaceStep(). Make sure that the platform body never collides another infinite mass object using groups, layers or callback filtering.

Animating constraints: Create a body with an infinite moment of inertia, otherwise create the body and shape normally. Also add a pivot joint between the body and the static body using cpPivotJointNew2(). Attach the anchor for the body at cpvzero, and the one for the static body at the desired position of the platform. It's also a good idea to set a max force for the joint. Each frame, move the static body anchor to the position you want the platform to move to.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 9 guests