Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: krmko on January 28, 2017, 07:11:29 AM

Title: Detaching children on collision [SOLVED]
Post by: krmko on January 28, 2017, 07:11:29 AM
Hi,

i'm using Core Gamekit together with playmaker for my game. I made some missiles that have a child particle system for trail generation from a spritesheet. As you know, when the particle system object is destroyed, particles don't finish their lifetime and die, but die instantly. That poses a problem since when the missile hits the target and explodes all the particles disappear at the same moment too.

I tried putting the particle system on a child prefab and detaching it upon impact, but it seems that the despawn of the missile and the detachment happen in the same update period, so it doesn't work properly. Any elegant ideas on how to solve this, i.e. make the particle system object detach properly? Listening to the missile hp doesn't work, and getting the distance is also useless since missile hits the collider which is way off from the object center.
Title: Re: Detaching children on collision
Post by: phannDOTde on January 28, 2017, 01:26:29 PM
On impact => destroy self (on the missile main object) check "detach children"

Alternatively use the "next frame" action to first detach you children emitters before destroying your missile?

For the children emitters I once used a solution where I check the particle quantity via "get property" before despawning them - if I remember correctly.

hope this helps :-) 
Title: Re: Detaching children on collision
Post by: krmko on January 28, 2017, 01:46:51 PM
Hmm. I've got to see if destroying (i guess that means deinstantiating) will bring the object back to pool, since i'm using pooling via core gamekit. But you game me an idea, i'll try it out and report back!
Title: Re: Detaching children on collision
Post by: Champ on January 28, 2017, 05:36:45 PM
The parent object doesn't need to be despawned on collision. it just needs to not be drawn and not be interactable with the other objects.

Its' renderers and colliders can be turned off for the set period of time needed for the particle effect to finish what you want, then when that's done you can run a despawn self or something. Keeping your prefab intact.

You'd need to remember to turn those thing back on in your initialise state on respawn

I'm pretty sure I read that turning colliders on/off won't mess up the physics engine and force a recalculation. It's only when you mess with the rigibody component that it happens.
Title: Re: Detaching children on collision
Post by: krmko on January 29, 2017, 12:28:47 AM
Hi, i actually i managed to pull it off meanwhile. I tried getting the parent, and when object is null, the particle system should disable itself. But it's never null, it just goes back to the pool.

So i did it like this:

Set the missile to have X number of hit points and HP Death Mode to Zero Hit Points
On Collision2D Store Collider (enemy that's been hit)
Send an event to detach the child object
Apply damage to collided game object and then X damage to itself

It all happens in two frames, so it looks simultaneously done.

@champ

That looks reasonable, but i'd have to mess with stopping the missile upon collision so the smoke trail doesn't go on, this seemed simpler that turning off the collider, renderer and the movement and then turning them on again.
Title: Re: Detaching children on collision [SOLVED]
Post by: Champ on January 30, 2017, 09:32:56 PM
Hey you got it to work, thats whats important :]