Bounce, stick, ..
-
- Posts: 6
- Joined: Sun Oct 12, 2008 3:11 pm
- Contact:
Bounce, stick, ..
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
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
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Bounce, stick, ..
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:
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)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 6
- Joined: Sun Oct 12, 2008 3:11 pm
- Contact:
Re: Bounce, stick, ..
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
"Set the shape of the ball to be a sticky shape" how do I do this ?
Thanks a lot !
ÔFred
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Bounce, stick, ..
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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 6
- Joined: Sun Oct 12, 2008 3:11 pm
- Contact:
Re: Bounce, stick, ..
Ok thanks !!
That works great !
That works great !
-
- Posts: 6
- Joined: Sun Oct 12, 2008 3:11 pm
- Contact:
Re: Bounce, stick, ..
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
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
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Bounce, stick, ..
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.
At this time, you cannot free objects that you remove from a space during a collision callback.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 6
- Joined: Sun Oct 12, 2008 3:11 pm
- Contact:
Re: Bounce, stick, ..
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 ?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Bounce, stick, ..
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.
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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 6
- Joined: Sun Oct 12, 2008 3:11 pm
- Contact:
Re: Bounce, stick, ..
ok Thanks for the tips !!! It simply works great !
Who is online
Users browsing this forum: No registered users and 13 guests