playMaker

Author Topic: Trigger 2D - Check for zero objects in trigger zone?  (Read 1537 times)

jameskyle

  • Playmaker Newbie
  • *
  • Posts: 15
Trigger 2D - Check for zero objects in trigger zone?
« on: October 06, 2014, 11:17:16 AM »
Basically as the title says. I need to check a trigger (BoxCollider2D with is trigger = True) to see if any objects occupy that space, preferably with a specific tag though this is not absolutely necessary.

So far I've been experimenting with trigger 2D event and get trigger 2D info without success. I'd thought that the the get trigger 2D info shape count property would offer a count on the number of objects in the trigger but either this isn't the case or I'm doing it wrong.

I've a feeling there is a fairly simple solution to this problem I'm just not seeing. Can anyone give me any advice on this? I'd greatly appreciate it. :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trigger 2D - Check for zero objects in trigger zone?
« Reply #1 on: December 29, 2014, 02:34:46 AM »
Hi,

I would keep a counter, that you increment on trigger enter and decrement on trigger exit. then if it's 0  it means it's free.

 and then given this, you can filter counter update based on a certain tag or layer.

this approach is the most performant, you could use trigger stay, but that means you would get events fired always when your space if occupy, it's unecessary really.

Bye,

 Jean