• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Pause a path (path_position or other)

Hi everyone.

I have an NPC that walks along multiple paths between rooms. Each rooms has its own path.
Basically, if one path ends, the next one begins. This ensures that once the NPC is at the door, its
"inside" path properly ends, and the "outside" path can only begin if the first one ended.

Now, what I need to do, is have the NPC stop for a while along the first path. I've been searching and searching and I can't get it to work, except when I figure out the path_position. I can also get it to work at specific x and y coordinates of the NPC, but that doesn't help me because the next step would be to stop the NPC in his path ifi the player "talks" to him, meaning x and y along a path need to be paused and need to be dynamic.

Just figuring out the path_position is a pain as it is a float between 0 and 1, but it works. However, that won't work if it needs to be dynamic. Some pause points are static, like specific room coordinates, other pause points need to be dynamic, like wherever the NPC is when the player talks to him.

I came to the conclusion that I need to dynamically , ingame find a way to pause the path_position. To my surprise, there is no easy function for this. There has to be a way right?

This seems like SUCH a common thing to do that it can't be that hard.
 
What do you mean by behaving weird?
Well since I deal with path transfer between rooms, I need my NPC to ALWAYS know the proper coordinates. This does not work easily in GMS2. So what I did was have an NPC be persistent, and set a path per room. If the player is the room where the NPC is supposed go to be, the NPC becomes visible.

In order for this to work, in the NPC's room end event, I put:
path_end()
Path_Position = path_position

In the room start event:
path_start(....)
path_position = Path_Position

In the step event I update which path. If one path reaches path_position = 1 , the next one starts (for a new room). I also have an animation system in there.

Now when I have the NPC at specific coordinates and say path_speed = 0 , he twitches, as if he constantly wants to continue, but stays put. He rapid switches between a ''left sprite'' and ''front facing sprite''
 

rIKmAN

Member
Well since I deal with path transfer between rooms, I need my NPC to ALWAYS know the proper coordinates. This does not work easily in GMS2. So what I did was have an NPC be persistent, and set a path per room. If the player is the room where the NPC is supposed go to be, the NPC becomes visible.

In order for this to work, in the NPC's room end event, I put:
path_end()
Path_Position = path_position

In the room start event:
path_start(....)
path_position = Path_Position

In the step event I update which path. If one path reaches path_position = 1 , the next one starts (for a new room). I also have an animation system in there.

Now when I have the NPC at specific coordinates and say path_speed = 0 , he twitches, as if he constantly wants to continue, but stays put. He rapid switches between a ''left sprite'' and ''front facing sprite''
That sounds more like something is being set somewhere else in your code and not taking into account that he has stopped, rather than the issue being with setting path_speed to 0.

You'd be best off using the debugger to step through the code by setting a breakpoint just after you make him stop (path_speed = 0) and tracing it through to see what is happening and where to cause those issues.
 
That sounds more like something is being set somewhere else in your code and not taking into account that he has stopped, rather than the issue being with setting path_speed to 0.

You'd be best off using the debugger to step through the code by setting a breakpoint just after you make him stop (path_speed = 0) and tracing it through to see what is happening and where to cause those issues.
I actually figured out something right now. I can get at least something to work, still got more learning to do however, so this comment is more about the engine than about me:

So I have this "point" where I want an NPC to pause in a path. It SPECIFICALLY SAIS x = 456 and y = 582 in the path editor (GMS2). It LITERALLY sais that in the path. yet, if want to pause the NPC, even by something as super easy as:

if x = 456 && y = 582

it doesn't work. The NPC ignores it and continues.


HOWEVER

if I say:
if x = 456 && y 581 (so 1 integer below the actual path y coordinate)

...
He does it. Like, whatever code i put it, it works. What the actual hell? The engine clearly states 582, yet it only works at 581.
Quick note: if i display a debug text it states 581.00 (point zero zero, doesn't do that with x for some reason)

What is going on here? Paths are so hard to understand in this engine... Like I can get it to work now, except I feel like I'm missing something here.
 
Top