Hello everyone, I am not using an Engine (this is for an authoritative server in Golang). I've tried going with the flocking approach but got wonky and horrible movement. Looked into A* and into dijkstra, but cannot for the life of me figure out how to go about modifying it to fit my needs and also keep it from burning out the CPU.
I'll explain the game briefly before going into technicals. The game is an auto battler and this video explains the idea ( https://youtu.be/h1Ijo8ew6CM?t=490 ), you can just watch the first 10 seconds or so of the fight.Your units start at 1 end and the opponent's units at the other, you meet up at the middle and attack the closest unit while avoiding allies and colliding with foes. I've looked into doing this with just raycasting but dropped that, I am now looking into grid based movement but I don't like that, I want for the units to feel like they're actually walking at different speeds rather than traversing the grid.
Any and I mean any direction or resource/ project would be mega helpful. I am stuck on this for 4 days now and it has been infuriating. I've gotten so far with the boids but it couldn't work out in the end. I think that some sort of gridbased movement is the way to go, but I cannot fully incorporate avoiding units and movement speed into this. The server ticks every 200ms and that's when the updates are called.
(There are no obstacles outside of units, and maybe some spawned obstacles because of abilities)
EDIT: I just have an ECS working so I can start from scratch, so any help is appreciated, I will provide more info if needed. I really want to get this going as it's super fun. Any help no matter the depth and complexity of it is appreciated
Ideally an idea on how to calculate all positions in advance in a way that everyone goes on their way without issues, as its only controlled by the AI this kind of calculation can be possible. I am just not understanding how to pace out my grid, what size should it be? The game would be around 1280x800 with 32x32 sprites, so if I want to more a unit to X grid, how do I know if the whole unit will fit? As the grid size is maybe 8x8 or 16x16 and that gridspace may be free but the one next to it wouldn't.
Unit pathfinding and avoidance related to all other units
My thoughts: If units can't stack then you have a grid of locations one unit width apart. 2d array.
At start of combat all units select a preferred target co-ordinate from this grid based on simple algorithm. It looks like units mostly just advance across x axis until they get into range of enemy? You could have units selecting target enemy units, or swapping a few random y axis so it looks cooler than everyone just rushing left/right in a line.
Each loop you just move each unit one at a time, trying to get closer to the target grid location x would be plus or minus 1, y would be plus or minus 1. If location is blocked by another unit then try find another location closer to target area. Check if in range of enemy target and stop movement and start attack. If no enemy in range call “find target” routine to set units desired location so it starts movement each loop again.
I don't think this would kill the CPU.
You could refresh target location for each unit a few times a second if you want to and it doesn't take to much processing power.
By avoiding any complicated pathfinding code (just simple is x+1,y closer to my target square?) it would be very fast code.
Hope my explanation makes sense.
@TheBlackRattie @undefined But if multiple enemies attack an enemy, I'd still need some kind of pathfinding to go around them?
your server ticks at 200ms… well if you could improve on that u would definitely benefit from A* or dijsktra,
here is a javascript based: https://www.gamedev.net/forums/topic/708293-new-pathfinding-viewer/
@amarillion wrote this and could give u pointers to get going
Until then ?
Yeah, I can give you some pointers on A* pathfinding.
But in the video you linked, the battlefield is completely open, no fixed obstacles at all. Is that true for the whole game? In that case A* might be overkill, and I would go more for the approach @TheBlackRattle is advocating. So basically make units move as a squad, in a continues path towards their target.
A* helps you route around fixed obstacles. But if you treat moving obstacles as fixed obstacles, then it's going to look weird.
I want for the units to feel like they're actually walking at different speeds rather than traversing the grid.
It's possible to use a grid and still have units traverse them at different speeds. You can track units' fractional positions within a cell in the grid, or use different time delays for each unit, before the unit moves to the next cell.