1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Pause a path (path_position or other)

Discussion in 'Programming' started by ZombieSquirrel, Nov 7, 2019 at 5:55 PM.

  1. ZombieSquirrel

    ZombieSquirrel Member

    Joined:
    Oct 18, 2018
    Posts:
    111
    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.
     
  2. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,611
    Set path_speed to 0?
     
  3. ZombieSquirrel

    ZombieSquirrel Member

    Joined:
    Oct 18, 2018
    Posts:
    111
    Yeah I checked that too, but I see the NPC behave weird if I do that strangely enough.
     
  4. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,611
    What do you mean by behaving weird?
     
  5. ZombieSquirrel

    ZombieSquirrel Member

    Joined:
    Oct 18, 2018
    Posts:
    111
    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''
     
  6. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,611
    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.
     
  7. ZombieSquirrel

    ZombieSquirrel Member

    Joined:
    Oct 18, 2018
    Posts:
    111
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice