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

GameMaker [SOLVED]Direct object to start of set path then to start_path() until told to chase player again.

  • Thread starter GamemakerTrialUser1
  • Start date
G

GamemakerTrialUser1

Guest
I've spent 5 / 15 days gone so far on the trial trying to solve this issue i'm having with Motion Planning with paths.

Lets dive into it shall we?

//Enemy Step Event - taken out of context as this is the only part of the code that I can't get to work the way I want:

Code:
dir = E_Scatter();
        if (x = 1050 && y = 630) {
            dir = path_start(p_G1,move_speed,path_action_restart,false);
        }

//E_Scatter() Script - just copied and pasted from my chase script. instead of xgoal and y goal being the player, i've changed the co-ordinates to correspond with the start of the set path (p_G1):

Code:
/// E_Scatter();

global.G_Path = path_add();

if (mp_grid_path(egrid,global.G_Path,x,y,1050,630,false)) { // 1050 and 630 are starting point for path p_G1.
    path_start(global.Ghost_Path, move_speed, path_action_stop, false); // move_speed = 1;

    var xx = path_get_point_x(global.G_Path, 0); // this section I copied from a youtube vid. lost the vid.
    var yy = path_get_point_y(global.G_Path, 0); // and don't fully understand it, but it works for chase.player.
    
    if            (x < xx) { dir = 0; }    //right   
    else if    (x > xx) { dir = 2; }    //left   
    else if    (y > yy) { dir = 1; }    //up
    else if    (y < yy) { dir = 3; }    //down
    
    path_end();
    path_delete(global.G_Path);
    
    return dir;
}
I know it isn't right but my lack of experience with the software doesn't help me figure out how to achieve my goal.

what happens?

the enemy indeed moves to the specified co-ordinates. But upon arrival, it wanders up and down a couple of tiles in an endless loop
To recap:

I want the enemy object, whilst it is normally chasing the player - after declaring its state from chase to scatter, will instead move wherever it is in the mp_grid to the start point of the set path [x1050,y630,p_G1]

Once the instance reaches those exact co-ordinates, i want to end the current direction / path and make the instance follow the set path [p_G1] until i change it's state back to chase.

I feel so close to resolving this but just spent too much time reading and researching i've confused myself over so many subtle changes. I'm hoping the problem is obvious.

Any advice and help would be greatly appreciated. If i can fix this issue, it''l help me fix other issues as i require a similar setup in future objects... [/gamemakerstory]
 
G

GamemakerTrialUser1

Guest
I've manually told the object where to go using objects as nodes. See the following:

Step Event // changed from code in above post

Code:
if (estate.scatter) {
        switch (Node) {
        case PStart.N1:
            if (mp_grid_path(egrid,PS1,x,y,o_G1PS.x,o_G1PS.y,false)) {
            path_start(PS1,move_speed,path_action_stop,false);
            var xxx = path_get_point_x(PS1,0); var yyy = path_get_point_y(PS1,0);
            if        (x < xxx) { dir = 0; }    //right  
            else if    (x > xxx) { dir = 2; }    //left  
            else if    (y > yyy) { dir = 1; }    //up
            else if    (y < yyy) { dir = 3; }    //down
            }
        break;
        case PStart.N2:
            if (mp_grid_path(egrid,PS1,x,y,o_G1PS1.x,o_G1PS1.y,false)) {
            path_start(PS1,move_speed,path_action_stop,false);
            var xxx = path_get_point_x(PS1,0); var yyy = path_get_point_y(PS1,0);
            if        (x < xxx) { dir = 0; }    //right  
            else if    (x > xxx) { dir = 2; }    //left  
            else if    (y > yyy) { dir = 1; }    //up
            else if    (y < yyy) { dir = 3; }    //down
            }
        break;  
        case PStart.N3:
            if (mp_grid_path(egrid,PS1,x,y,o_G1PS11.x,o_G1PS11.y,false)) {
            path_start(PS1,move_speed,path_action_stop,false);
            var xxx = path_get_point_x(PS1,0); var yyy = path_get_point_y(PS1,0);
            if        (x < xxx) { dir = 0; }    //right  
            else if    (x > xxx) { dir = 2; }    //left  
            else if    (y > yyy) { dir = 1; }    //up
            else if    (y < yyy) { dir = 3; }    //down
            }
        break;  
        }
    }
This works but its messy to me. Too many steps. I could place this in a script and call it.

I'll make a video on this once I buy the software so other people can refer to it. It's very handy to have. Still gutted that I couldn't figure out how to use my set path instead of resorting to nodes. Hopefully ill learn that one day.
 
Last edited by a moderator:

Nidoking

Member
I think the problem was that the speed was greater than the distance to the destination, so it was jumping back and forth over the destination without ever landing exactly on it. You can check that distance and either jump the instance directly to the goal if it's going to pass it on the current step, or set the speed temporarily to exactly that distance so it lands where you want it to.
 
G

GamemakerTrialUser1

Guest
nice, what are you working on?
Making my own Pacman game. But before I make my own version, I'm trying to code the game to the original to gain an appreciation for the Ghost AI, so that I can tinker with my own enemy ghosts to pursue Pacman differently. In other words, to give them different personalities to the originals. I'll have a youtube series up before May focusing on everything I've done. Hoping by then I'll have completed making it. See attached image. The blue ghost is what I've been working on. The above code is a snippet of it's AI movements. As of now, I have actually pretty much finished it. Just testing to remove bugs here and there then I'll be on to the Red or Pink ghosts.

For anyone wondering, the Blue ghost in this picture is actually coded to the Original game's red ghost - possibly the easiest to code of the four imo.

I think the problem was that the speed was greater than the distance to the destination, so it was jumping back and forth over the destination without ever landing exactly on it. You can check that distance and either jump the instance directly to the goal if it's going to pass it on the current step, or set the speed temporarily to exactly that distance so it lands where you want it to.
I had it set at 0 instead of 1, which matches the movement speed. Discovered this when simplifying the step event with a new script Impressed you figured this out just reading the above code. Kudos to you!
 

Attachments

G

GamemakerTrialUser1

Guest
i did the same. you will need this gift :).

http://tralvex.com/download/forum/The Pac-Man Dossier.pdf

let me know if you need any advise on the AI
I've glossed over that dossier but should really take note!

I think the way i'm doing things, it's much more complicated than it needs to be :/ for example, the tiles from the dossier look like tiles, whereas mine are grid lines.

I couldn't figure out how to get the ghost to head towards a fixed target tile outside the map without just moving forever into a wall. You've reminded me that I haven't coded in the fact that the ghost can not go backwards,
even though in many circumstances it does at present. So if you can help me code a way so that if the ghost gets towards a fixed target tile, it has to loop back around -hence the scatter mode, that'd be very helpful.

Heres a close up shot of the grid lines...
 

Attachments

Sabnock

Member
the original doesn't use paths at all but uses instead a simple grid cell based system as you mention. the ghosts look for a target tile that is calculated differently for each ghost to give the impression if an intelligent system. it is beautifully simple.

you are correct that the ghosts cannot move backs and can only go forward or turn left or right(from their perspective). the targeting system uses some basic trigonometry.

"I couldn't figure out how to get the ghost to head towards a fixed target tile outside the map without just moving forever into a wall" the trick to this is the perpetual forward or turn mechanics. if a ghost is heading towards a target but hits a wall it will turn left or right depending on the options but always continuously move. if you watch the original on youtube you will see that sometimes, mainly in scatter mode, that the ghost appear to be circling an area. this is because they are attempting to reach a target they cannot get to because it is out side of the maze so they continue to move forward and take the only turns that are available to them.

this is my attempt at it. it became a passion for me to get as close to the original as i could. if you hit escape and turn on the debug mode you'll see the ghost AI at work.

https://forum.yoyogames.com/index.php?threads/original-pac-man-1980-edition.34015/
 
Last edited:
G

GamemakerTrialUser1

Guest
Wow! Mine looks turd now thanks haha I see prefectly well now how the tile system works. back to the drawing board for me. Thanks for sharing. Good to know someone out there accomplished the very thing i've set out to do. Great work on your own game!
 
G

GamemakerTrialUser1

Guest
:( this was not my intention. it is an amazing game and if i can save someone months of doing it wrong and steer them in the right direction then all good :)

shout if you want to go through anything.
Haven't done a U-Turn but definitely took a different route. Decided I'd mimic the original map design. My room resolution was 1080p!! I've opened a new room and manually drawn all the tiles to match the original. It all looks better already. Realised all my sprites need to be top left and not middle centre so they appear in the tile and not the grid.

Learned loads from your game alone. Love that debug mode. Thanks again. I'll keep you posted and appreciate the offer of help.
 
Top