Advertisement

Unit movement for a battle simulator type 2D game (custom engine)

Started by April 14, 2021 08:27 AM
5 comments, last by sir7 3 years ago

Hello everyone. Firstly I'd like to explain my setup. Here is the image of the battlefield https://imgur.com/a/AW8UVWr

The setup is as follows:

- Custom Engine. 5 steps a second (server ticks)

- Units are 32x32 (for the time being)

- Map size is 800x512 divided into 4x4 tiles. I am doing this as it's the best solution for pathfinding, general computation of collision, location, etc. (Movement speeds are measured in how many 4x4 tiles they traverse in a step).

- Units are purely AI controlled no interference from the user

The general movement flow would look like this :
1) AI finds the closest/ the best unit to go towards.
2) Movement handler finds a free spot near that target and marks it as goal (so other units dont path towards that point), then generates a path with A*, marks a couple of steps ahead that the unit will traverse that path so that other units dont path and interfere.
3) Movement system moves the unit ahead x tiles.

This in theory looks okay, but it has a lot of flaws:
1) It doesn't work at the moment, as placing two units next to each other breaks them both because of the mark system presumably (marking the path makes both unable to traverse it)
2) A* is used even tho I have no obstacles besides other units. I'd like to switch to Jump Point search probably.
3) I have to recalculate the path every single time the destination (goal) changes. And that often happens, for example, we have two units. Unit A targets unit B and in reverse, every time they move towards each other, the goal has to change and the path has to be recalculated even tho the path is going towards the target properly.
4) Units should probably move together and be aware of each other's paths somehow.

Basically server ticks 5 times a second, AI generates actions for AI to perform, Handlers handle the actions, Systems do the other work necessary. But I cannot think of a good flow for the movement to work properly. Now they are either getting stuck in each other or not moving at all. I don't need a smart AI, just good enough to go to the enemy, avoid others, take a free place next to that enemy and go on from there.

Units always start at the opposite sides of the battlefield.

I'd appreciate any thoughts/ theory/ articles/ tutorials/ books. I've been reworking the movement system for the third time now and it's been really tiresome. Any help is appreciated, please feel free to ask for any additional details if necessary!

sir7 said:
I don't need a smart AI, just good enough to go to the enemy, avoid others, take a free place next to that enemy and go on from there.

If this isn't smart AI, I don't know what is.

For AI group movement, there's a technique called flow field pathfinding.

Here's flow field pathfinding vs A* in action:

Advertisement

And here's a video of an explanation of how this works

@undefined yes thank you. I am doing Flow Fields and Boid like movement. Some kind soul on Stackoverflow mentioned those and never responded again but it got me going.

As for the AI smartness, I said ‘dumb’ as predictable and just doing the bare minimum needed to do its task, eg go to enemy, attack the enemy.

Can I ask you something more specific about this topic later on? I already have a concern about the amount of loops used, and some other behaviour when it comes to surrounding the unit. But I am still not at the stage to worry about those.

Late response from me but hopefully this is still useful.

If you'll forgive the shameless plug, I've written some notes about flowfields, other pathing techniques and boids on my RTS tech blog. It might be of interest to you.

@jdtec01 I've actually extensively analyzed your boids article already!

This topic is closed to new replies.

Advertisement