playMaker

Author Topic: Tracking multiple objects within a FOV  (Read 166 times)

LordHorusNL

  • Junior Playmaker
  • **
  • Posts: 78
    • View Profile
Tracking multiple objects within a FOV
« on: July 08, 2017, 08:18:26 AM »
Hey guys, so i'm workig on a AI system for my game and i'm trying to figure out the best way to check if other NPC's are within a certain field of view.

Tracking one object is simple offcourse, however i need to check the angle/visibility of multiple objects from an array list to see if they move in/out of the FOV.

This array list is populated with objects that are in close proximity to the NPC doing the checking, so this list changes depending on the objects in range.

So i never know how many items are in the array at any given time.

Any ideas on how to best approach this?
« Last Edit: July 08, 2017, 08:20:26 AM by LordHorusNL »

tcmeric

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Tracking multiple objects within a FOV
« Reply #1 on: July 08, 2017, 08:33:03 AM »
I think this could be made by using FSMarrays. As mentioned in other thread, I worked a little bit with the author of this asset for some actions. He is always open to suggestions and is playmaker savvy as well. If not, I can assist in adding more actions for it.

Sensor Toolkit: https://www.assetstore.unity3d.com/en/#!/content/88036

It includes FSMarray actions already. You can add FOV using colliders, rays, etc. It can then filter by results by tags, etc. Then you have a nice FSMarray of gameobjects within FOV. Its pretty well optimized. Clear instructions, etc.

In my own person project, I ended up dumping my own FOV scripts and in the process of implementing this asset instead :)


LordHorusNL

  • Junior Playmaker
  • **
  • Posts: 78
    • View Profile
Re: Tracking multiple objects within a FOV
« Reply #2 on: July 08, 2017, 08:47:32 AM »
The Sensor Toolkit does look like it has most of the functionality that i need and i might need to consider it, however i'm going broke buying all the stuff unity seems to lack :P

If i may ask,how dit you approach this issue in your own playmaker project using FSM's?

« Last Edit: July 08, 2017, 09:04:42 AM by LordHorusNL »

tcmeric

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Tracking multiple objects within a FOV
« Reply #3 on: July 08, 2017, 10:06:51 AM »
As gameobjects enter into your FOV (collider, raycast, depending on how you decide to do it), then you need to add them to a FSMarray.

Something like, have a collider area for your FOV. Once something enters into your FOV area, check the tag or layer to make sure its an enemy. If true, then draw a raycast (or line cast) to the object to see if you have a direct line of sight. If true, then add object to your FSM array.

To see if you still have line of sight, you need to keep checking with the ray cast (I suggest setting it as specific intervals, rather than everyframe). Or if not import, dont keep checking, and just use your collider area exit. If the raycast is false, because you no longer have FOV, then have it removed from your array.

tcmeric

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Tracking multiple objects within a FOV
« Reply #4 on: July 08, 2017, 10:07:43 AM »
PS, there is a great tutorial series on AI from Bill on youtube. Its very comprehensive, and he covers line of sight, collider areas, etc. I really recommend it. https://www.youtube.com/watch?v=nsbczU2b4EM

He shows how to do everything I mentioned, except the array I think. But thats the cherry on top. If you get his system working, adding array after will be easy.

LordHorusNL

  • Junior Playmaker
  • **
  • Posts: 78
    • View Profile
Re: Tracking multiple objects within a FOV
« Reply #5 on: July 08, 2017, 10:43:24 AM »
Yep watched all the tutorials, i'm was hoping to not have to use a loop to keep checking the objects, however i now see that checking at intervals will be necessary.

I had all that working already, it was just the multiple target thing i had a problem with.

Thanks for the tips, i'll see if i can integrate it into my system, and if not i'll have to purchase the asset you recommended.

LordHorusNL

  • Junior Playmaker
  • **
  • Posts: 78
    • View Profile
Re: Tracking multiple objects within a FOV
« Reply #6 on: July 09, 2017, 02:37:56 PM »
I figured the system out and it was working fine, however the lack of an adjustable FOV cone turned out to be to much of a hassle. So i ended up purchasing the sensor asset.

The Tag system does not seem to work for me, so i'll contact the seller but overall it's pretty good so far.

Quick question about something else, the "Set Animator Look At" action, does this only work when running from a FSM on the object with the animator component?