playMaker

Author Topic: Is it possible to make an enemy or NPC search for tagged items?  (Read 683 times)

Migsterium

  • Playmaker Newbie
  • *
  • Posts: 6
Is it possible to make an enemy or NPC search for tagged items?
« on: November 13, 2020, 12:06:32 PM »
Hey there! I'm working on a 3D scene where an enemy navigates through a maze looking for a key item, and the player has to follow the enemy to exit the maze (but not too closely lest the enemy notices them and attacks).

I used Nav Mesh to tell the enemy which obstacles/walls it should avoid on their way to the key items scattered around the maze and the Set Agent Destination As Game Object Playmaker action to tell the enemy where it needs to go.

Since there are multiple key items, I've been creating multiple states inside the enemy's FSM which change the enemy's current destination from one key item to the next in an endless loop (unless the player enters the enemy's search radius in which case the enemy stops looking for the key items and instead hunts down the player).

My question is: instead of making a new state for every single item/destination that the enemy must search, is there a way to tell the enemy to move towards any random GameObject with a KeyItem tag, and once it reaches its destination to move to another random KeyItem?

heavygunner

  • Sr. Member
  • ****
  • Posts: 344
Re: Is it possible to make an enemy or NPC search for tagged items?
« Reply #1 on: November 13, 2020, 10:57:41 PM »
May be Find Closest 2 can help. You can find object by Layer. This can be found in Ecosystem browser

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Is it possible to make an enemy or NPC search for tagged items?
« Reply #2 on: November 14, 2020, 06:21:00 AM »
Hi. you could use a Overlap Sphere.

I would suggest not to use every frame but use it for example every second or so.

after you do overlap sphere you can loop thru the items and use get distance.

First use Array Get (index 0) then loop thru rest with Array Get Next (set Start Index to 1)

and compare the distance. if closer, save distance and object in a variable to compare. (also the 1st one should be stored in these variables.)

you could also use Array Maker and get a custom action Array List Cast Overlap Sphere.
Then use Array List Get Closest.