Detect the presence of actors in an area
henriquesv
Member Posts: 18
Hi!
I have a few actors in a scene. I want to detect the presence of the ones that are contained in an specific area. And then I want to count how many of them are there.
I tried to use an extra actor, like an invisible square and then use collision to increment or decrement a game variable as they enter or exit this area. The actors themselves would + or - this variable as they collide or not. But this approach makes these actors to stop moving as they enter this area (invisible square).
Any ideas?!
Thanks!
Comments
I'd have tried the same thing!
There must be a reason they stop when they enter the area though - do you have a 'collide' behaviour in the 'area' actor.
You don't need it if you do, or shouldn't anyway.
QS =D
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
You should use Magnitude function - it calculates the distance between 2 actors so you could have an attribute Integer that ticks +1 every time magnitude distance is less than some value
Magnitude is fine but if you want an area thats an odd shape see the file attached, just a very quick demo for you.
Hope its useful.
Darren.
No.. I had this 'collide' behaviour then I took it off. There is no collide behaviour in the area nor the actors.
What I am trying to do now is:
The thing is that.. instead of +1 and -1 for each actor entering or leaving the area the counting is going over like -159.. +200...
I think you're on the right track - the thing to do is to make sure that if the moving actor has already been counted, don't count it again.
How many actors does your design have in total that can be counted? 5? 10? 100? More? Might be useful to know for possible solutions.
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
I had a similar situation like this, but only when actors were on the full screen. Adding variables like that seemed to only work part time. If you're having trouble with that... the way I did it was have a built in timer (mod01>self time%.5) and the actors send their time every .5 seconds to the variable... then on the object they're overlapping... if selfTime>1 second then do... so the object looks at the time, and the actors reset the time every .5 seconds, but when they're gone they don't reset the time and the time goes on, when it hits 1 second then the object knows there's no more actors there.
I posted a demo above guys did you miss it?
Darren.
Hi Darren! I think I missed your demo for a few minutes!
Excellent example! I was detecting collision while detecting touch / dragging.
I thought that the system would keep incrementing the game's attribute. But it only happens the first time it overlaps or it is free of overlapping.
Hi QS! I am working with 16 actors and 4 kinds of them. Also 4 area actors.
So 16 actors (4 x 4 kinds) or 64 (16 x 4 kinds)? :O
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
4 x 4 kinds .. 16 actors.
I followed Darren example and it workd fine for 1 collision area.
But now I am trying to do it for the 4 collision areas.
So, area 1 needs to know how many actors of each kind is inside them.
Like:
Area 1:
actor A: 2
actor B: 1
actor C: 0
actor 1
the same goes for Area 2, 3 and 4.
I am trying to replicate the Rules for each Area. Using some kind of "LastHotspot" the actor was in.
Two issues so far:
1) GameSalad system is getting waaaaay too slow.
2) Seems like it is ignoring the "LastHotspot" attribute. I have tried both "Save Attribute" and "Constrain Attribute" if it is colliding with the Hotspot/Area.
I'm thinking this could be done pretty easily in tables, especially in the latest nightly/release candidate.
You could set up a table - 16 colums, 4 rows.
The columns will count which of the 16 actors are in which area (defined by the rows).
Sorry, I'm not a clever thinker, more a brute force logic kinda guy!
QS =D
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
Is there anyway to set an actor's attribute as soon as it is spawned?
Should I just create a sentence Saving its attribute? I don't want this sentence to run again.
I am thinking about setting each actor for a column attribute. So as long as they are being spawned I would set them from 1 to 16.
Afterwards I would check each for collision and then fill the Table in.
As an example, I usually do:
If some.variable = 10
And
check.variable =0
Change check.variable to 1
So essentially it's checking to see if the variable is 0. If it is, it'll change it to 1. If it's already 1, it won't do anything.
Make sense?
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
I'll think about it and let you know! Thanks QS!