• 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!

How do I get POKEMON monster follow effect [SOLVED but not perfect]

N

Neo

Guest
I am trying to snap an object to my previous snapped position to create following object. Something like the old pokemon follows you around. I think it is easy enough but cant seem to make it work any ideas? In my code now it snaps right on top of me. I need to figure out a way to make the cage object always snap to me but be one snapped position from me for example if I am at x=16 y=16 then i move to x=32 y =16 the cage should be at my previous snapped position 16,16, but with my code it snaps to my current position 32,16. I know it is simple just can't figure it out.

if place_snapped(16,16)
{
if x!=cageSnapx
cageSnapx=x
if y!=cageSnapy
cageSnapy=y
}

I then have a following object called cage that has this in the step event
x=obj_man.cageSnapx
y=obj_man.cageSnapy
 
Last edited by a moderator:
N

Neo

Guest
This should be simple but it is got me stumped any advice?
 
Last edited by a moderator:
N

Neo

Guest
I dont know why my code isnt working.

My thought is that once the man is snapped it records those coords in cageSpapx and cageSnapy variables. The next time the character is snapped to grid and the new position is different from the previous the new coords are recorded. But it isnt working
 
N

Neo

Guest
I figured it out my self there is probably a better method but this is what I ended up doing The code works great except the cage will sometimes be diagonal with the player instead of matching his previous movement. Maybe someone can come up with better method IDK. Not many in this forum anymore.
if place_snapped(16,16) //if aligned with grid, stop movement
{
if x==cageSnapx+32
{
cageSnapx=x-16
cageSnapy=y
}
if x==cageSnapx-32
{
cageSnapx=x+16
cageSnapy=y
}
if y==cageSnapy+32
{
cageSnapy=y-16
cageSnapx=x
}
if y==cageSnapy-32
{
cageSnapy=y+16
cageSnapx=x
}

}
 
Last edited by a moderator:
Top