Page 1 of 1
Bounce, stick, ..
Posted: Sun Oct 12, 2008 3:19 pm
by OFred
Hello,
I'm new with this beautiful library. To learn how to use it I just want a ball to bounce on the left/right walls and stick on the top wall. And when I throw another ball, I want it to stick with other balls, and top wall but bounce on the left/right walls.
To do this I tried two things:
1) Playing with elasticity and friction coefficient, but I dosn't work.
2) I use cpSpaceAddCollisionPairFunc to detect the collision with the top wall, then I set the velocity of the ball to 0 and I remove the collisionPairFunc (to save cpu?!) It's OK.
I add another addCollisionPairFunc to detect collision between two balls and set their velocity to 0 but it doesn't work the way I want
Can someone explain me the best way to do this ?
Cheers,
ÔFred
Re: Bounce, stick, ..
Posted: Sun Oct 12, 2008 4:28 pm
by slembcke
Depends on how solid you want them to be after they get stuck.
If you want them to be bouncy like this:
http://www.youtube.com/watch?v=0VuB2XFMHk8 you will need to create joints and springs.
If you just want them to be completely solid, that is easier. Make a collision callback between the ball and "sticky" objects. The callback should do the following:
- Set the velocity of the ball to (0,0)
- Set the mass and moment of inertia to infinity
- Set the shape of the ball to be a sticky shape
- Remove the ball's body from the space (don't free it until the game is done)
This way the ball stops moving, becomes static (you set it's mass properties to infinity, and removed it from the space), it becomes part of the sticky geometry.
Re: Bounce, stick, ..
Posted: Mon Oct 13, 2008 3:31 am
by OFred
Wow It's exactly the kind of game I would like to dev !!
"Set the shape of the ball to be a sticky shape" how do I do this ?
Thanks a lot !
ÔFred
Re: Bounce, stick, ..
Posted: Mon Oct 13, 2008 9:37 am
by slembcke
I don't mean that there are stickiness parameters in Chipmunk. I mean to use the collision type to identify which are sticky and which are not and let the collision pair callback to the rest.
Re: Bounce, stick, ..
Posted: Wed Oct 15, 2008 6:53 am
by OFred
Ok thanks !!
That works great !
Re: Bounce, stick, ..
Posted: Sat Oct 25, 2008 1:40 pm
by OFred
I'm back, life is not so easy
I think there is a good place to remove a shape:
i've tried to do it in the Collision callback but it's freeze and die which leads me to the cpArtiber.c file line:
con->r1 = cpvsub(con->p, a->p);
I think it tries to access the destroyed shape ?!
It's hard to dev with something we don't know how it works.
Can someone help me ?
Cheers,
OFred
Re: Bounce, stick, ..
Posted: Sat Oct 25, 2008 4:42 pm
by slembcke
Oh, sorry. It looks as though I forgot to copy the section on collision pair functions over from the old documentation. I'll have to get that added back.
At this time, you cannot free objects that you remove from a space during a collision callback.
Re: Bounce, stick, ..
Posted: Sat Oct 25, 2008 5:17 pm
by OFred
In your game scribBall, after an animation you make the ball disapear (explosion) So, when do you free objects ? Not in the collision pair function ?
Re: Bounce, stick, ..
Posted: Sat Oct 25, 2008 5:23 pm
by slembcke
No, we use the collision pair functions to find groups of like colored balls. After the physics step is complete, we run a graph algorithm to find all the groups larger than 4.
Now that I'm thinking about it, it wouldn't really be all that hard to change so that you can remove the objects inside of a collision pair function. For now, you'll just have to make a list of the objects that you want to remove and then remove them once cpSpaceStep() returns.
Re: Bounce, stick, ..
Posted: Sat Oct 25, 2008 6:16 pm
by OFred
ok Thanks for the tips !!! It simply works great !