Hello Guest

Author Topic: Possible to detect trigger enters with each frame?  (Read 6336 times)

mphilips

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Possible to detect trigger enters with each frame?
« on: July 18, 2014, 03:04:35 am »
I'm still new to 2D tool kit & unity but I noticed when I play an animation it will only detect the initial trigger enter event and any further frames will not register a trigger event. Is there a way around this? Basically I have a 2d top-down shock wave and I have it set up so anything in the shock wave is killed. The box collider around the shock wave gets larger with each frame so I just need a way to  have a trigger enter event take place with each frame.

If it works, it should be able to destroy game objects as the shockwave increases.

Any ideas or help would be appreciated!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Possible to detect trigger enters with each frame?
« Reply #1 on: July 18, 2014, 02:42:54 pm »
Do you have a kinematic rigidbody on it, and are you using 2d or 3d physics?

LaserDinosaur

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Possible to detect trigger enters with each frame?
« Reply #2 on: July 18, 2014, 05:45:11 pm »
If the OnTriggerEnter2D method is on your explosion sprite, it could be triggering for the first entity it kills but is not leaving that entity before hitting a new one (So it doesn't fire a new OnTriggerEnter2D).

You could move the trigger event onto the entities that are being hit by the explosion - that way they are all monitoring their own OnTriggerEnter2D event.

If you want to leave your trigger on the explosion, you might be able to use OnTriggerStay2D - this will fire every frame that an object is detected within the explosion collider. However, this might still just keep returning the first entity that triggered the OnTriggerEnter2D, so not sure if that would work.
« Last Edit: July 18, 2014, 05:55:08 pm by LaserDinosaur »

mphilips

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Possible to detect trigger enters with each frame?
« Reply #3 on: July 18, 2014, 07:20:47 pm »
Do you have a kinematic rigidbody on it, and are you using 2d or 3d physics?

Yep, with 3D physics. Haven't tried the 2D Physics engine yet.


I'm still new to 2D tool kit & unity but I noticed when I play an animation it will only detect the initial trigger enter event and any further frames will not register a trigger event. Is there a way around this? Basically I have a 2d top-down shock wave and I have it set up so anything in the shock wave is killed. The box collider around the shock wave gets larger with each frame so I just need a way to  have a trigger enter event take place with each frame.

If it works, it should be able to destroy game objects as the shockwave increases.

Any ideas or help would be appreciated!

I'll try putting a trigger event on the individual objects. That might actually work. Basically, anything in the initial activation of the explosion sprite is destroyed properly, but nothing happens during any other frames in the animation as the sprite/collider increases in size.

mphilips

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Possible to detect trigger enters with each frame?
« Reply #4 on: July 19, 2014, 01:19:12 am »
Well, I gave it a try but no luck : (

It works exactly like before -> Initial frame triggers enter event but no other frames do. So the group of enemies in the starting collider are killed and they trigger fine, but everything "touched" by the collider as it grows in the other frames do not trigger their events at all.

I'm using the smoke cloud from the example as a test object right now. I set the scale to 72x72 to fit in the current scene. The box collider is set for each frame in the editor and it looks okay in the scene, but it doesn't seem to touch enemies after the first frame. 

Is it possible I am missing something in the settings for 2D Toolkit or should this be working like I said?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Possible to detect trigger enters with each frame?
« Reply #5 on: July 19, 2014, 04:43:37 pm »
This has nothing to do with tk2d here, its unity physics its using. I could take a look if you post a repro...
Also, it might be worth trying 2D physics, it does work quite differently.

mphilips

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Possible to detect trigger enters with each frame?
« Reply #6 on: July 20, 2014, 01:25:53 am »
Turned out it was an issue with 3D Physics. The moment I switched over to 2D it worked perfectly. Thanks for the suggestion.