Creating a lever

Official forum for the Chipmunk2D Physics Library.
Post Reply
Deception55
Posts: 6
Joined: Sun Jul 17, 2011 7:59 am
Contact:

Creating a lever

Post by Deception55 »

good morning everybody!

I'm trying to create a simple lever, like the one in figure

Image

I want the user move his finger where the arrow is, and have load jumping depending by the speed of the movement

I'm using Chipmunk and SpaceManager

I've tried a lot of time, but seems I'm not able to do that…

the method that looks similar to what I want is the SpaceManager method

Code: Select all

/*! Explosion, applied linear force to objects within radius given a group and layer(s) */
-(void) applyLinearExplosionAt:(cpVect)at radius:(cpFloat)radius maxForce:(cpFloat)maxForce layers:(cpLayers)layers group:(cpGroup)group;
but this only apply a force in the center of the object and it's not what I need…

I tried to divide the object in little parts, and the applyLinearExplosionAt works… but I can't glue the parts! if I merge the shapes obviously the forse is in the center of the merged shape…
I tried to use pin joints, but they are unstable, and I couldn't find a more "solid" joint…

The idea now is to create a little shape where the user have is finger, and one again everytime he moves… then the shape will fall with an high speed and with a mass decreasing (and destruct the object when ir have mass 0)… the gravity shoul do the rest of work...

but I think that spamming object like this is not a very efficient way…

so… help! (I've a feeling the solution is really easy)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Creating a lever

Post by slembcke »

Create a shape when you start a touch event and remove it when the touch ends. You can update the finger object's position/velocity like the mouseBody in the official Chipmunk demo app.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Deception55
Posts: 6
Joined: Sun Jul 17, 2011 7:59 am
Contact:

Re: Creating a lever

Post by Deception55 »

I forgot to write it! that I tried this too...
But what happens is that if I make a quick movement the object crosses the lever without moving it...

maybe I can try again this way, and change something...
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Creating a lever

Post by slembcke »

Well in the chipmunk demo code I smooth out the motion of mouse to help avoid this. You can also explicitly clamp the distance it can move each frame too.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Deception55
Posts: 6
Joined: Sun Jul 17, 2011 7:59 am
Contact:

Re: Creating a lever

Post by Deception55 »

ok!
at least now I know there's not an obvious way to do that! ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests