[ZScript] A* Pathfinding

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm

[ZScript] A* Pathfinding

Post by dodopod »

This mod enables A* pathfinding through a network of Nav Points. In order to use it, you'll need to place Nav Points at all the intersections of your map. Connections between Nav Points are generated automatically. Then, create an actor descending from Pathfinder, and use the A_Star function where you would normally use A_Chase. There is a monster and a demo level included (type `map maze` in the console). I recommend using it with `am_cheat 2` so you can see the monster navigating the maze. This is just a prototype, so it isn't terribly optimized, and still has a few problems. Feel free to use or modify it, as long as I'm credited.

Download
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm

Update v0.2

Post by dodopod »

This update changes pathfinding so that it occurs through a navigation mesh built automatically from the level geometry. At present, the algorithm requires all reachable sectors to be convex polygons, though it tends to work even if they're not. In order to enable pathfinding, inherit an actor from Pathfinder. In addition to a 'See' state, it must also have a 'See.Plan' state. Then add these two action functions:

A_Chase2(StateLabel meleeState = 'Melee', StateLabel rangedState = 'Missile', StateLabel planState = 'See.Plan')

Makes the monster chase its target as long as they are in the same sector, or it has an up-to-date path to its target. Goes in the 'See' state.

Params:
  • meleeState: The state to jump to when the monster decides to perform a melee attack.
  • rangedState: The state to jump to when the monster decides to perform a ranged attack.
  • planState: The state to jump to when the monster doesn't have a path to follow.
A_Star(StateLabel meleeState = 'Melee', StateLabel rangedState = 'Missile', StateLabel seeState = 'See')

Creates a plan to reach the target, or waits if it's unreachable. Goes in the 'See.Plan' state.

Params:
  • meleeState: The state to jump to when the monster decides to perform a melee attack.
  • rangedState: The state to jump to when the monster decides to perform a ranged attack.
  • seeState: The state to jump to when the monster finds a path.
Download
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] A* Pathfinding

Post by Major Cooke »

Heh, pretty nice. Shame this doesn't work for maps like this.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [ZScript] A* Pathfinding

Post by Nash »

Wow, this is interesting!

What would be cool is to see the navmesh build around solid actors (for things like static mesh decorations), and to see chase movement that is velocity-based instead of step-based (so that the monster can smoothly rotate in more than 8 angles and not have stepped movement). :D
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: [ZScript] A* Pathfinding

Post by ZippeyKeys12 »

Nash wrote:What would be cool is to see the navmesh build around solid actors (for things like static mesh decorations), and to see chase movement that is velocity-based instead of step-based (so that the monster can smoothly rotate in more than 8 angles and not have stepped movement). :D
It'd be better if there was a virtual function called (or first-class functions) that you could control movement from. Then you could decide between the base movement, steering behaviors or whatever your heart desires. Also objects should just be avoided with basic obstacle avoidance like ORCA or RVO, otherwise actors may hit each other in movement or even when one is static.
User avatar
Armaetus
Posts: 1256
Joined: Fri Mar 13, 2009 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10 Home
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: New York State

Re: [ZScript] A* Pathfinding

Post by Armaetus »

How does this handle with mods that alter monsters? Would be interesting to see Oblige generated maps using this..
Drake Raider
Posts: 474
Joined: Fri Jul 18, 2008 12:27 pm

Re: [ZScript] A* Pathfinding

Post by Drake Raider »

Sorry to necro, but is there a way to make this universal at all?
I was thinking adding a generic tnt1 A_Star state to Actor, and replacing A_Chase's definition with that of A_Chase2, but I don't know enough about zScript to know if it works that way. Sure would make maps like Eternal Doom III great with custom monsters mods.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [ZScript] A* Pathfinding

Post by Nash »

@dodopod: how do you set this up with doors? It seems to not do any planning at all as soon as I cross into and beyond a door sector. I've tried all the door specials. Also doesn't seem to plan successfully if there the ceiling is too low (but still passable/walkable). I am trying this with v0.2.
User avatar
Cherno
Posts: 1321
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript] A* Pathfinding

Post by Cherno »

I only ever used the initial version (no use for a nav mesh), and I just dug into the code which ios fairly easy to understand, and edited the way connections are made between points to my liking. For example, I aded a linetrace function.
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England

Re: [ZScript] A* Pathfinding

Post by Hidden Hands »

If anyone can help clarify how to script this I would be most appreciative. Just took a look and it's very much on the lines of what I'm looking for, but I cannot get to grips with how to make this work in my game.
User avatar
Cherno
Posts: 1321
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZScript] A* Pathfinding

Post by Cherno »

1. Place NavPoints around the map.
2. Have an actor inherit from Pathfinder.
3. [Optional] Set a target for the actor (optional because this is commonly done by A_Look for monsters automatically)
4. Instead of A_Chase,have the actor call A_Star to follor the path (if any).

Return to “Script Library”