Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Logic behind AI auto-generating waypoints for enemies in tower defense

A topic by spraypaintdev created Jun 13, 2024 Views: 263 Replies: 9
Viewing posts 1 to 3

I want to make a tower defense game but with a twist, the waypoints are generated instead of predefined

This isn't really something new, so if you know the logic behind it, please do share.

(1 edit)

It's pretty simple if I'm understanding right. You use code to have the waypoints generate enemies, but to generate the waypoints, you have to use a sort of Create Object function and for the X and Y coordinates of it, use random values.

For example, if you had a room that was 1280x720, you could put something like this for the X and Y coordinates:

X: 200 + random(880)

Y: 200 + random(320)

This creates randomly placed waypoints, but with a 200 pixel border around each part of the room.

That one sounds good but the problem is that formula could cause enemies to walk ontop of towers. I also need these waypoints generated in such a way so that they can try to get out of reach from enemy towers 

(1 edit)

Create a separate object of the same size as the waypoint, and make that object invisible.

Upon creation of this new object:

X: 200 + random(880) for the new object

Y: 200 + random(320) for the new object

Check for a collision against tower:

If new object is in collision with tower,

X: 200 + random(880) for the new object

Y: 200 + random(320) for the new object

else:

Create object waypoint (newobject.x, newobject.y)

Delete the instance of the new object

nice 

(1 edit)

Also, if you want the space surrounding the tower to be avoided as well, create an invisible object that stretches across that whole territory, and have this "New Object" talked about in the previous post avoid that instead of the tower.

Is this not just a pathfinding problem? Discretize your world into tiles, slap on A*, where the cost function depends on distances to buildings/turrets/anything unwanted by your enemies.

could you show an implementation in python with tensorflow?

(2 edits)

I cannot show you A* pathfinding with Tensorflow because that’s got nothing to do with it. Look it up.

oh ok