Making a paddle...

Official forum for the Chipmunk2D Physics Library.
mani2009
Posts: 5
Joined: Tue Nov 17, 2009 8:36 am
Contact:

Making a paddle...

Post by mani2009 »

Hi, just started using chipmunk( good work btw), and i am try to make a paddle for a pinball type game.
Have started with a rectangle using the demo code but i am a bit lost on how to make a pivot type motion.
Demo 7 has a pivot joint example but it looks more like a rope than a paddle.
Demo 8 has apply force example to make the paddle move "body->velocity_func = apply_force;"
It is basically a "door opening" type movement i want to create. Any ideas?

this is what i have so far

Code: Select all

	int num = 4;
	cpVect verts[] = {
		cpv(-15,-15),
		cpv(-15, 15),
		cpv( 35, 15),
		cpv( 35,-15),
	};

	body = cpBodyNew(1.0, cpMomentForPoly(1.0, num, verts, cpvzero));
	body->p = cpv(-280, 240);
                body->velocity_func = apply_force;
	cpSpaceAddBody(space, body);
	shape = cpPolyShapeNew(body, num, verts, cpvzero);
	shape->e = 0.0; shape->u = 1.5;
	shape->collision_type = 1;
	cpSpaceAddShape(space, shape);
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Making a paddle...

Post by slembcke »

Here is how I would do it. Create a body with an infinite mass and moment of inertia, this is the body for the flipper. Don't add the body to the space because you are going to control it manually instead. Create the shape for the paddle, a simple fat line segment or box will do. Add the shape as a normal shape as it will be moving around. Make the center of gravity to be where you want it to pivot. That way all we have to do is rotate the body, and the shape will rotate around the pivot point.

Now, to control the body, you will have to update both it's rotation and angular velocity. When a key is pressed, rotate the body towards the activated position a little each frame. Calculate the angular velocity as (newAngle - oldAngle)/timestep. When the key is released, rotate it back the other way.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mani2009
Posts: 5
Joined: Tue Nov 17, 2009 8:36 am
Contact:

Re: Making a paddle...

Post by mani2009 »

Thanks, got it working, any idea what values of e and u to use to model a pinball? or is it to do with the gravity value set for the space?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Making a paddle...

Post by slembcke »

Not really sure. I'd probably start with e=0.6 and u=0.4. That is just an educated guess though. Experiment and adjust.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mani2009
Posts: 5
Joined: Tue Nov 17, 2009 8:36 am
Contact:

Re: Making a paddle...

Post by mani2009 »

Thanks
pabloruiz55
Posts: 22
Joined: Mon May 18, 2009 7:31 pm
Contact:

Re: Making a paddle...

Post by pabloruiz55 »

Sorry to hijack this thread but i also need to make a flipper for a pinball game and was playing with that.

Is it possible to create a pin joint at the point it should rotate and then on update check if the rotation is higher or lower than some number and don't let it rotate past that number?
Is there another way of not letting it rotate past certain angles?
If i do this i would only have to apply an impulse to the other side of it to make it hit the ball.


If i go the "static shape with manual movement" way, would the hitting part be correct? i mean if the ball is near and i make it hit it by adjusting the rotation manually would it hit the ball correctly? I it doesn't, how could i apply an impulse to the ball that simulates the correct behaviour?

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

Re: Making a paddle...

Post by slembcke »

In Chipmunk 5 there are angular limit joints that will let you limit the rotation.

For something fast moving like the pinball paddle, I'd still go with the manually controlled approach. It's a little more work, but a lot more likely to look realistic instead of really bouncy/spongy.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pabloruiz55
Posts: 22
Joined: Mon May 18, 2009 7:31 pm
Contact:

Re: Making a paddle...

Post by pabloruiz55 »

Hi, thanks for the answer!

I am trying to do what you posted before, but how can i change the center of gravity so when rotating it doesn't rotate form the center but from the "anchor" ?
pabloruiz55
Posts: 22
Joined: Mon May 18, 2009 7:31 pm
Contact:

Re: Making a paddle...

Post by pabloruiz55 »

Ok, i figured that out.

The problem is that i did everything that is posted here but manually rotating the flipper is making the ball go through it... any idea? Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Making a paddle...

Post by slembcke »

You mentioned "static shape" before. Are you actually adding the paddle as a static shape? Static shapes don't update their collision detection info and cannot be moved. You need to add them as normal shapes.
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: No registered users and 16 guests