Ghostly movement routine

Im making a pacman type game, im storing the ghosts x y in a 2d array for direction checking, the ghosts are 32 x32, i need a movement routine that allows the ghosts to move at different speeds but only by 32px before they have check if a new direction is possible

Huh?? What’s the stay on screen got to do with working out where to move to every 32 pixels?


It’ll be a bit of a hack, but here’s a solution that would work :

  1. Add pathfinding behaviour to the ghost object, and use a virtual cell grid of 32x32.
  2. Find a path using Move ghost to position... to get the initial path.
  3. Then get the first node’s X & Y position using ghost::Pathfinding::NextNodeX() and ghost::Pathfinding::NextNodeY()
  4. Change path of ghost by using Move ghost to position... and use the X & Y values you got out of the previous step.

Alternately, use pathfinding, and use a timer to determine when to look for a new path (e.g when timer > 1 second, search for a new path).

1 Like

I may have misunderstood

Thanks, ive written my routines to be modular so i can just add any movement routines on the end, i’m trying the tween extension at the moment, all ghosts running around randomly but they look a little jerky, is there any setting i can change?

Will give your suggestion a try though!

What easing function are you using? I’d have though linear would give a fairly smooth appearance. Anything else would give a continual speeding up and slowing down effect.

Yes im using the linear easing, im moving them 32 px which is 1 cell in the array then it goes back to the routines to check possible moves, so there seems a slight hesitation every move of 32 rather than it looking like a smooth continuous movement

This suggests that there could be improvements made to your events. Could you screen snip your events. and we may be able to advise on fixing it?

Thanks for having a look,
i have 2 states, 0= check for next move, 1= move ghost, the variable moving1 controls which state it is at, Variable Ghost1_direct contains the output from my array movement checker for the next direction, 1=left, 0=right, 3=down and 2=up, the code snippet is my quick hack to get tween working so will not be the best even by my low standards.

just cleaned a few variable out that i had left in but still much the same

Ive found if i precalculate the destination, store it in a variable and check this instead of using the has tween finished it seems a little smoother

Do you think if i checked if the tween was only nealy finished before starting the next tween it would look like one continuous movement, though im not sure how to do this

You’re checking for a tween named “up” , but you’ve misnamed the tween “down”.

Changed it, also changed it to 1 check for moving1 and all below to a subroutine

Can you also post the events that determine which way to move?

this gets what is located in the four directions around the ghost, input is Row_check and Col_check, output is the cell values u, d, l and r, i think this may be the bottleneck and i may need to expand it to 32 col/rows, so may have to seek another solution rather than using an array

this is the next code that take the output of the above checks which direction and sets the reverse direction as my ghost can only reverse if they meet each other.

next takes the possible moves and picks a random one

final routine to to pass on the direction and set what is the reverse direction

This looks messy and is not doing what I think you expect it to do. Your events are checking the 16 cells to the right of the Ghost object position. Even if it’s in the last column. That last event (increase row_number) is outside the first Repeat 16 times, and has no effect on the cell checking.


I’m assuming you just want to check the 4 cells around the ghost object? There will be a much better way than using an array. That’s obsolete, old school 8-bit computer technique. What does the information in each cell give you? Just the cell number the ghost can move to? Is the game made up of a grid that the ghost object can move along?

In fact, can you describe what you are trying to achieve? We should be able to help you get a solution that’s tidy, efficient and expandable, so you can change the grid size to however big you want it without impacting on performace.

I am from the 8bit school!, the array contains just 1’s if there is a wall and 2 for a blank space, yes it just gets back is it a 1 or 2 in the 4 cells around the ghost object which is used by the other routines to determine which directions are possible, well what im trying to achive firstly is to learn Gdevelop and secondly end up with a nice pacman style game with 4 independent ghosts that i can swap out the random move routine to more intelligent ai

Amstrad FTW :partying_face:


You might be better off to ditch the routine you’ve got, and look at path finding. It will be a bit simpler to create semi decent appearing ai. Effectively you give the object a target position, and it will work out the best path to get there. You can then re-evaluate at any point along that path if you like, or let it run through to it’s destination.

Thanks, i will have a look into this and whatever i do i will have learned alot about gdevelop