Looking for feedback on NPC pathing system

Started by FortressCaulfield, Tue 19/11/2024 15:32:23

Previous topic - Next topic

FortressCaulfield

Wanted a system for moving NPCs who aren't in ego's room. For a guard pacing back and forth, you could just leave him where he is and restart him when ego comes back. But in some cases I need to more accurately simulate the walk, so that if ego walks into a room where he is, he's in the right spot and continues. Like if that same guard needs to walk 4 rooms away and check something. And I needed it to be simple cuz I'm not actually that good at this. :D

made a struct steps, with x, y, room and type. Type is enum to sWalk, sHalt and sRoom.

Added to player properties int activestep, defaulting to -1.

Was not able to figure out variable length arrays or use pointers to tie paths and chars together, so I cheated. I just have one array that holds all the paths in the game. When it's time for scott to go to the shoe store, you set his activestep to whatever the first step of that path is. (0, if it's the first or only path.)

Room loads check if activestep != -1, run do_path for that char and step. Do_path reads that step in the array, and does what's needed, with the char either walking or changing rooms or stopping and ending the path.

Global rep exec checks if activestep != -1 and if the char is moving. If they're not, that means we've either interrupted a walk by changing rooms or he's at the end of a step. Run the current instruction. Do_path checks if they've reached their x/y destination, and if they have, increment activestep.

Here's the clever and/or stupid bit: chars can't walk in rooms the player isn't in, so instead we yeet them into a virtual room with y position 2000 greater than their actual coordinates.

When an NPC on a path changes room, they ALWAYS change to the room where the player is. If that room is the real room they're meant to be in, they use their real coordinates. If it's not, they use coordinates with y + 2000.

This means for the actual movement we just just issue normal char.walk commands, with noblock and anywhere.

The NPC's movement plays out naturally in real time, with the very same commands. Correct positioning and walk progress is maintained if the player walks in on the NPC or vice versa.

Current issues:
if the NPC's walk animation plays sounds, the player will hear it when the NPC is in the virtual room.

no way to make NPC wait or pause. Can use a very long step on a room the player can never reach or can simply make multiple paths as a work around.

Probably several other hideous flaws I'm just not seeing yet.
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

eri0o

#1
Stupid question, did you considered making a big AGS room and make your game rooms in this? Assuming you don't need this for all of the actual game but just an area. You could fake them being separate rooms by carefully controlling the camera. Things like game resolution and room size must be considered though since they impact this. Also how they are designed so that characters could flow in a way that is consistent.

FortressCaulfield

that's an interesting idea, but I think that would be way harder unless you were running a really low res game or a specialty game where you need to track precise movement for all chars at all times in a small space, like among us set in a house.

Basically what I'm doing is pathing the NPC in a virtual room 2000 y south of the actual room, so the walk command can handle their pathing. It was the smoothest solution I could think of.
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

eri0o

In ags4, you could use the MaskPathFinder to pathfind in some arbitrary sprite and then move in this path something that is invisible, then you could scale down the size of the mask and make the invisible character move at a scaled down speed too, and then it's about connecting the two worlds. You can do something similar in your case with adjustments, you don't need to use the actual same characters.

SMF spam blocked by CleanTalk