How is Built-in Chase Scripted?
Moderators: marionline, SDHawk
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
How is Built-in Chase Scripted?
I was wondering what the formula/script is for the engine's built-in chase move type?
I want to know if chase works in a completely predictable way or if there is some randomness to which direction the NPC moves when there are two equally good paths between the Hero and NPC.
I want to know if chase works in a completely predictable way or if there is some randomness to which direction the NPC moves when there are two equally good paths between the Hero and NPC.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
With 50% chance, it tries to move closer to the hero in the X direction, otherwise in the Y direction. Strangely, if it already has the same X or Y coordinate, then it moves in a random direction with uniform chance. (It would only be necessary to move in a random direction if there is actually an obstacle). This is all done before checking for obstacles.
So this means that chase NPCs chase you faster when they're moving diagonally rather than in a straight line.
Here's the code (from pick_npc_action in game.bas), with the parts for wrapping maps and Flee NPCs removed for simplicity
So this means that chase NPCs chase you faster when they're moving diagonally rather than in a straight line.
Here's the code (from pick_npc_action in game.bas), with the parts for wrapping maps and Flee NPCs removed for simplicity
Code: Select all
IF randint(100) < 50 THEN
IF caty(0) < npci.y THEN temp = 0
IF caty(0) > npci.y THEN temp = 2
IF caty(0) = npci.y THEN temp = randint(4)
ELSE
IF catx(0) < npci.x THEN temp = 3
IF catx(0) > npci.x THEN temp = 1
IF catx(0) = npci.x THEN temp = randint(4)
END IF
npci.dir = temp
IF temp = 0 THEN npci.ygo = 20
IF temp = 2 THEN npci.ygo = -20
IF temp = 3 THEN npci.xgo = 20
IF temp = 1 THEN npci.xgo = -20
Last edited by TMC on Wed Mar 15, 2017 10:44 pm, edited 3 times in total.
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
- Taco Bot
- Meat, Cheese, and Silicon
- Posts: 484
- Joined: Fri Jul 18, 2014 12:15 am
- Location: Santa Cruz
- Contact:
Ooh! If you add/change movement types, maybe add the ability to change the wait between steps with the wander move type. IIRC it's currently random? It feels a little twitchy, and it'd be nice to make NPCs seem slower without making their movement speed 1. (And in higher FPS games, that still seems fast)
Sent from my iPhone
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Starting with the current nightly wip build, there are two new NPC movement types
"Chase You (Direct)" and "Avoid You (Direct)"
The old semi-random Chase/Avoid types have not been changed, but they are now named "Chase You (Meandering)" and "Avoid You (Meandering)"
Direct Chase prefers to close the shortest distance first.
Direct Avoid prefers to lengthen the longest distance first.
Neither is smart about going around obstacles. That sort of thing will have to wait for some other new movement type in the future.
EDIT: (My gif recorder peppers the bottom half of the screen with random white pixels. I also notice that when I try to upload to imgur, it gets almost done with the upload (I can even see the preview animating) and then it fails with an unknown error. Opening and re-saving the animating gif with the Gimp fixes my upload problem)
"Chase You (Direct)" and "Avoid You (Direct)"
The old semi-random Chase/Avoid types have not been changed, but they are now named "Chase You (Meandering)" and "Avoid You (Meandering)"
Direct Chase prefers to close the shortest distance first.
Direct Avoid prefers to lengthen the longest distance first.
Neither is smart about going around obstacles. That sort of thing will have to wait for some other new movement type in the future.
EDIT: (My gif recorder peppers the bottom half of the screen with random white pixels. I also notice that when I try to upload to imgur, it gets almost done with the upload (I can even see the preview animating) and then it fails with an unknown error. Opening and re-saving the animating gif with the Gimp fixes my upload problem)
Last edited by Bob the Hamster on Tue Mar 21, 2017 6:00 pm, edited 1 time in total.
- sheamkennedy
- Liquid Metal Slime
- Posts: 1110
- Joined: Mon Sep 16, 2013 9:29 pm
- Location: Tama-shi, Tokyo, Japan
- Contact:
@Bob:
Thanks so much for adding this. I think the direct movement types will work a lot better for what I'm currently working on. I have started developing a tactical rouge lite where the enemies move every time you move and I want the enemies to close in on you as fast as possible in a fairly predictable way. Obstacle avoidance is not necessary in most cases.
Thanks so much for adding this. I think the direct movement types will work a lot better for what I'm currently working on. I have started developing a tactical rouge lite where the enemies move every time you move and I want the enemies to close in on you as fast as possible in a fairly predictable way. Obstacle avoidance is not necessary in most cases.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
â� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
- Taco Bot
- Meat, Cheese, and Silicon
- Posts: 484
- Joined: Fri Jul 18, 2014 12:15 am
- Location: Santa Cruz
- Contact:
So I just got the zaniest idea: could you use this, in combination with restricted zones, to make (somewhat) complex npc movement patterns without using scripts? Aka: you could give them a weaving perimeter to pace by surrounding them with avoid zones?Bob the Hamster wrote:And a super cool thing about follow walls, is if an NPC has its movement restricted by zones, then those zones count as walls too
Sent from my iPhone
- Bob the Hamster
- Lord of the Slimes
- Posts: 7658
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
Yep! :)Taco Bot wrote:So I just got the zaniest idea: could you use this, in combination with restricted zones, to make (somewhat) complex npc movement patterns without using scripts? Aka: you could give them a weaving perimeter to pace by surrounding them with avoid zones?Bob the Hamster wrote:And a super cool thing about follow walls, is if an NPC has its movement restricted by zones, then those zones count as walls too