Borderwall and pathfinding, cant get it to work :/

Hi,

After I found GDevelop and did a fun project, I wanted to make my dream game, a maze tower defense game!

But now I’m really stuck and i have a couple of problems i really don’t know how to solve.

  1. Problem, the enemies are going outside the gameboard, i have tried to look at tutorials on how to close of the game so they cant run offscreen, but i really cant get it to work.

  2. Sometimes the units are stuck in spawn and don’t go towards the castle in the bottom, this happened when i tried to close of the off-screen problem with the archer towers (which has collision)

  3. How do i make the board so the player only can put the towers in certain areas?

Object screen:

Events screen:

Many thanks for the help!

Note: I created a lengthy reply. It might be too much information but the better you understand the process, the easier it will be.

The border objects don’t appear to have an image because it’s showing an x in a circle. Without an image it won’t have a collision mask (hit box) The size of the image doesn’t matter. You can hide them at the beginning if you don’t want then to be visible.

Also, for some reason rotated objects become passable. So, instead of rotating an object, resize it in the other direction . Make sure the border object has the pathfinding obstacle behavior.

When you use the pathfinding move action the path to the destination needs to be reachable as well as the final destination. The entire object’s collision mask must fit. There’s a condition to test if the path is found. It can be inverted so it can test for not found. There’s another condition for destination is reached.

Pathfinding can use a lot of resources so try to use it sparingly. If there aren’t any moving obstacles and the destination isn’t changing then you can move the move action to the same event that adds the object. Just put it right after the add action. That way it only calculates the path once.

If you need to continuously update the path you can use a timer so it doesn’t update the path on every frame and/or calculate the path only when certain times like when the object is close to the target or maybe if the object stops or the destination isn’t reachable.

It’s not a major issue with a simple path with a small number of obstacles and objects following the path. I don’t have any numbers but it can manage a lot of things but if you notice a lag then you might need to optimize it. For now, it’s fine to just get your test project to work and worry about optimizing it later. While keeping the issue in your mind.

The behavior uses a grid to create a path. If the scene has close obstacles, you might need to spread them apart or decrease the pathfing grid size for the x and y. I find that 10,10 works. If the grid is too small, it will require more processing time to create a path.

I hope some of this helps. There are examples you can try plus if you search for posts with my username, I made some projects you can also try. Note: the playable link might not still be valid but the github link should be.

As far as limiting where the towers can be place, what are the restrictions? Any suggestions would just be guesses.

1 Like

Thank you for taking your time! Really appreciate it, and ill test out what you wrote!

Regarding the restrictions, i seeking to have “tiles” where the player can put the towers in, so they cant put them wherever they want to on the board!

Once again, thank you!

OK. You could have tiles that when touched or clicked would change to the tower or you could drag a tower and it could only be placed on a placeholder object. Or in a grid position. It depends on how you want the player to add the object. Either touch a location or drag from a tray or a combo of both.

You can search the forum for grid or drag grid.

I didn’t download the project bc I’m on my phone but this has an interesting drag demo.