Post new topic    
Page 1, 2  »
Liquid Metal Slime
Send private message
How is Built-in Chase Scripted? 
 PostWed Mar 15, 2017 10:00 pm
Send private message Reply with quote
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.
⊕ 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
Metal King Slime
Send private message
 
 PostWed Mar 15, 2017 10:40 pm
Send private message Reply with quote
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

Code:
    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
Liquid Metal King Slime
Send private message
 
 PostThu Mar 16, 2017 12:27 am
Send private message Reply with quote
I should make a few other NPC movement types. I know someday they will be scriptable, but that is no excuse not to add a few more hard-coded ones now
Meat, Cheese, and Silicon
Send private message
 
 PostThu Mar 16, 2017 4:15 am
Send private message Reply with quote
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
Metal King Slime
Send private message
 
 PostThu Mar 16, 2017 6:00 am
Send private message Reply with quote
Ah yes, Wander NPCs have a 1/4 chance to start a step every tick that they're not already walking. At 18 fps, that means they only pause for a ~fifth of a second, at higher frame rates it's no time at all.
Liquid Metal King Slime
Send private message
 
 PostTue Mar 21, 2017 5:58 pm
Send private message Reply with quote
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)
Metal King Slime
Send private message
 
 PostTue Mar 21, 2017 6:35 pm
Send private message Reply with quote
Seeing it in action, it seems more useful than I thought it would be!

(Oh dear. I knew that there's a bug in the gif encoder that very rarely inserts bad pixels, but this is the first I've seen where they're obvious; I guess I will have to look into it after all)
Liquid Metal Slime
Send private message
 
 PostTue Mar 21, 2017 7:33 pm
Send private message Reply with quote
@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.
⊕ 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
Liquid Metal King Slime
Send private message
 
 PostTue Mar 21, 2017 10:25 pm
Send private message Reply with quote
And next up we have "Follow Walls (Right)" and "Follow Walls (Left)"

These were fun to implement!

Metal Slime
Send private message
 
 PostWed Mar 22, 2017 12:07 am
Send private message Reply with quote
Oh man. I love these.
Meat, Cheese, and Silicon
Send private message
 
 PostWed Mar 22, 2017 12:29 am
Send private message Reply with quote
The follow walls one looks cool! I gotta think up some use for it. Reminds me of the spiky guys who float along walls in Super Mario Land 2 (or was it Wario Land?)
Sent from my iPhone
Liquid Metal King Slime
Send private message
 
 PostWed Mar 22, 2017 12:32 am
Send private message Reply with quote
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
Meat, Cheese, and Silicon
Send private message
 
 PostWed Mar 22, 2017 12:35 am
Send private message Reply with quote
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


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?
Sent from my iPhone
Metal Slime
Send private message
 
 PostWed Mar 22, 2017 12:57 am
Send private message Reply with quote
Oh my god. James just made MGS 1 & 2 style stealth gameplay possible using built-in NPC behavior and light scripting.
Liquid Metal King Slime
Send private message
 
 PostWed Mar 22, 2017 12:07 pm
Send private message Reply with quote
Taco Bot wrote:
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


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?


Yep! :)
Display posts from previous:
Page 1, 2  »