Pre collision callback HELP

Official forum for the Chipmunk Physics Library.

Pre collision callback HELP

Postby xcrunner509 on Mon Feb 08, 2010 6:44 pm

hi im wondering how would this lets say we have a block (Object-1) that is motionless in mid-air and then we have an shooter (Object-2) that is shooting at it and we want Object-1 to react how it would naturally once it was hit (It would then not become static and turn dynamic) Ie. if Object-1 gets hit from the bottom by Object-2 Object-1 would no longer be motionless and it would go up for a bit then gravity would push it back down... or if it were to get hit from the bottom right it would go up and to the left.... or if it were hit by another block hat is falling it would fall down also.

i realized that ti would have to use a pre collision callback function on the object1/2 collision that would replace static object 1 with dynamic object 1. i.e. add object 1's body to the space at that point. I'm pretty sure that would work. but i have no clue how to do this

If anyone could help me with this it would be greatly appreciated.
xcrunner509
 
Posts: 2
Joined: Mon Feb 08, 2010 6:38 pm

Re: Pre collision callback HELP

Postby slembcke on Mon Feb 08, 2010 9:55 pm

It's pretty simple actually. Create the body as normal (give it a normal mass), but do not add it to the space. Add the shape to the space as a static shape. Create a collision callback that does two things. 1) Add the body to space. 2) Remove the static shape from the space and re-add it as a normal shape.
I'm the guy that wrote Chipmunk. Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 1502
Joined: Tue Aug 14, 2007 7:13 pm


Return to Chipmunk Physics

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron