playMaker

Author Topic: Detaching children on collision [SOLVED]  (Read 806 times)

krmko

  • Sr. Member
  • ****
  • Posts: 458
    • View Profile
    • Fat Pug Studio
Detaching children on collision [SOLVED]
« 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.
« Last Edit: January 30, 2017, 12:28:29 AM by krmko »

phannDOTde

  • Full Member
  • ***
  • Posts: 233
    • View Profile
    • Peter Hann .de
Re: Detaching children on collision
« Reply #1 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 :-) 

krmko

  • Sr. Member
  • ****
  • Posts: 458
    • View Profile
    • Fat Pug Studio
Re: Detaching children on collision
« Reply #2 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!

Champ

  • Playmaker Newbie
  • *
  • Posts: 8
    • View Profile
Re: Detaching children on collision
« Reply #3 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.

krmko

  • Sr. Member
  • ****
  • Posts: 458
    • View Profile
    • Fat Pug Studio
Re: Detaching children on collision
« Reply #4 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.

Champ

  • Playmaker Newbie
  • *
  • Posts: 8
    • View Profile
Re: Detaching children on collision [SOLVED]
« Reply #5 on: January 30, 2017, 09:32:56 PM »
Hey you got it to work, thats whats important :]