playMaker

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

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Tracking multiple objects within a FOV
« on: July 08, 2017, 11: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, 11:20:26 AM by LordHorusNL »

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Tracking multiple objects within a FOV
« Reply #1 on: July 08, 2017, 11: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

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Tracking multiple objects within a FOV
« Reply #2 on: July 08, 2017, 11: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, 12:04:42 PM by LordHorusNL »

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Tracking multiple objects within a FOV
« Reply #3 on: July 08, 2017, 01:06:51 PM »
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

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Tracking multiple objects within a FOV
« Reply #4 on: July 08, 2017, 01:07:43 PM »
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.
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

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Tracking multiple objects within a FOV
« Reply #5 on: July 08, 2017, 01:43:24 PM »
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

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Tracking multiple objects within a FOV
« Reply #6 on: July 09, 2017, 05: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?

SamH

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Tracking multiple objects within a FOV
« Reply #7 on: April 24, 2021, 05:08:43 PM »
Just to add to this- thanks for the suggestion about Sensor Toolkit.. it's worked great in my project and I got it up and running with playmaker really quickly!