GM:S 1.4 [SOLVED] Object that follows in the Player's previous footsteps

Discussion in 'Programming' started by TheRBZ, Feb 22, 2019.

Tags:
  1. TheRBZ

    TheRBZ Member

    Joined:
    Feb 5, 2017
    Posts:
    98
    I've been looking through the manual to find a way to make an object follow the player while avoiding solid parts of the room, but I couldn't find a reliable way. The context here is I have an NPC that needs to follow the player.

    I thought about having the game remember the player's vsp (vspeed) and hsp (hspeed) every step and relay that for the following object but I didn't know how to get around this. I know that move_towards_point will not work because I have solid parts of my room that shouldn't be walked through.

    Paths looked like they could potentially work but they cannot be created 'on-demand' with the player's coordinates each x steps.

    Does anyone know how this could be undergone? Thanks.
     
  2. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    63
    paths actually can be made on the fly

    as for following behind I suppose the best way would be to save the last grid the player was in and set that as the goal so use something like this and instead do player.goalx player.goaly
    player object create
    goalx=floor(x/32)*32-32
    goaly=floor(y/32)*32
    lastx=floor(x/32)*32
    lasty=floor(y/32)*32

    player object step
    if lastx !=floor(x/32)*32 or lasty!=floor(y/32)*32{
    goalx=lastx;
    goaly=lasty;
    }
    lastx=floor(x/32)*32
    lasty=floor(y/32)*32
     
    TheRBZ likes this.
  3. TheRBZ

    TheRBZ Member

    Joined:
    Feb 5, 2017
    Posts:
    98
    Thank you, this video helped a bunch- I got what I needed working :)
     

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