Is there a way to make Monsters explore?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Duvo
Posts: 42
Joined: Thu Dec 26, 2019 4:17 am

Is there a way to make Monsters explore?

Post by Duvo »

Specifically, is there a way to make monsters rotate around all the sectors they can access?
I'm creating a mod where monsters duke it out deathmatch style and I need them to rotate
around the map when they're not fighting, looking for new targets.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Is there a way to make Monsters explore?

Post by Matt »

Trying to work out which ones they can access, without spending a lot of time having them go through all their surroundings by trial and error, seems to be the biggest issue.
User avatar
Caligari87
Admin
Posts: 6230
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Is there a way to make Monsters explore?

Post by Caligari87 »

I made a "searching" AI procedure that mostly works with existing A_Chase code.
  1. If the monster doesn't have a target pointer, create a path node somewhere nearby.
  2. Set the monster's goal pointer to the path node.
  3. When the monster reaches the path node, remove it.
    • If the monster doesn't reach the node in some reasonable time, remove the node and start over.
  4. Cast rays in a 180° fan from the monster's facing angle (I like to limit these to 512 units or so).
  5. Pick the longest ray and set a new path node at the end of it.
  6. Repeat.
While simple, I find this routine does well at making monsters that seem to "explore" spaces in a more ordered fashion than just calling A_Wander. Namely, they tend to avoid walls better (especially if the goal nodes are placed close together). It's also great at helping monsters "search" for the player if you set the first goal node to the player's position when they break line-of-sight. Obviously you can enhance this routine by checking for height differences, setting different criteria for the raycasts, etc.

Look at Josh771's universal Enhanced AI for a more complex implementation of this idea, using nested goal nodes to search each area the monster reaches before moving on.

8-)
User avatar
Duvo
Posts: 42
Joined: Thu Dec 26, 2019 4:17 am

Re: Is there a way to make Monsters explore?

Post by Duvo »

Thanks @Caligari87, I'm excited to try this out
Post Reply

Return to “Scripting”