How To Implement Precollision+Event.contact Into My Code?

Hi!
I have an enemy sprite object (parachuter) that has several sequences. It is created in the “air” with physics body and start sequence “paraglide” and then “glides” down to a platform (platform1) where it changes sequence to “paraLand” and then start “landing” and finally lands on a second platform (platform2). 

 

Now to my problem. If a hero shoots at the parachuter and hits with a bullet the parachuter changes sequence to “paraDead”. The dead parachuter should now ignore platform1 and then land on platform2. How do I do this?

 

This is my code:

http://pastebin.com/uM6ME3GQ 

 

I don’t want to remove the body and then add it again, because then the object will lose its velocity. I guess I need to use event listeners with precollision, but how should I do it?

 

Best regards,

joelwe

Hi @joelwe,

Here’s a tutorial on how to use the physics contact to selectively ignore collision with certain things.

 

http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

 

Brent

Hi Brent and thank you for your reply!
Yes, I’ve seen that tutorial and I’ve tried others too. This is what I’ve tried: 

 

(19-26 and and 36-37)

 

http://pastebin.com/syk8pCGe

 

With that code paraDead will both not collide with platform1 and platform2! I don’t know what’s wrong with it?

At a quick glance, I’m not sure where you’re getting or setting the “.Skipped” parameter and how that factors into the precollision filter. I’d do the precollision filter and check which platform the parachuter is colliding with using the “.myName” parameter.

 

Brent

YES! I FINALLY GOT IT!
 

http://pastebin.com/uM6ME3GQ

 

 

BIG thanks to alestane @ #corona: irc! :D and thank you too Brent for myName input! :smiley:

Hi @joelwe,

Here’s a tutorial on how to use the physics contact to selectively ignore collision with certain things.

 

http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

 

Brent

Hi Brent and thank you for your reply!
Yes, I’ve seen that tutorial and I’ve tried others too. This is what I’ve tried: 

 

(19-26 and and 36-37)

 

http://pastebin.com/syk8pCGe

 

With that code paraDead will both not collide with platform1 and platform2! I don’t know what’s wrong with it?

At a quick glance, I’m not sure where you’re getting or setting the “.Skipped” parameter and how that factors into the precollision filter. I’d do the precollision filter and check which platform the parachuter is colliding with using the “.myName” parameter.

 

Brent

YES! I FINALLY GOT IT!
 

http://pastebin.com/uM6ME3GQ

 

 

BIG thanks to alestane @ #corona: irc! :D and thank you too Brent for myName input! :smiley: