Project: Squad
Project Started: |
22nd September, 2011 |
Last Update: |
17th December, 2011 |
Project Owner: |
Muz |
Project Members: |
|
Project Type: |
Shooter management |
Project Progress: |
|
|
Coding a battle engine
Posted 27th Nov 11, by Muz
|
|
The battle engine will be 2.5D, which means that the characters will be somewhat side view, but be able to walk behind or in front of one another, even when overlapping. More importantly shots like bullets and rockets will go behind each other without overlapping.
It was initially a bit of a challenge to code, but one trick I found was to create sort of a XY base for the characters and objects in the game. Treat the base sort of like how you'd treat top-down code, which makes it simple 2D. Then add an extra Z (up-down) angle to it, and check whether the bullets go too high or too low.
Unlike the typical klik method, bullets won't be shot around and collision detected. It's quite possible to just collision detect, all I have to do is treat the shots like it's top-down, and check if that hits. If it does, check if the z-position is right for a hit to the head or feet or whatever. It's simple enough, but in my experience (and hearing about the experiences of many others), collision detection is buggy in MMF2. I'd rather spend an extra week working on the long route, than a few frustrating weeks debugging the collision detection, then giving up and passing down the frustration to the player.
So, simulation it is. The shots will be simulated by finding the angle and direction of the shot, and then adding a little inaccuracy to that angle. Then we trace where the bullet ends up. If the location of bullet is somwhere where there is already cover, then the bullet hits cover. If the bullet is aimed at someone's head, but the angle slides a bit and hits the arm instead, then it hits the arm. The more difficult problem seems to be checking whether a bullet hits cover, as there's too many bits of cover around.
There's a few approaches I've considered.
- The easiest method is just to scan through every bit of cover on the map and check if it hits anything. The problem here is that it's probably computationally intensive. You've got 6 sin/cos per bullet. With approx 40 parts of cover in a map, that's 240 per bullet... with 20 bullets flying around per second, 4800 sin/cos per second? It'll easily hit 10k+ with more bullets and a large map, with lots of units. It's not too bad with modern computers, still, it's a sloppy solution.
- A more classic approach, used by many games, is to determine sort of a cone of area where the bullet may go astray, and then choose something within this cone. It's not a bad approach at all, but I feel too much effort to code/debug.
- Another classic approach is to only examine the cover around the target, and check if it hits that (probably a higher chance of hitting cover the further away the shooter is). Then sort of draw a line from the shooter to the target, and tick and check everything along the way. I think games like Jagged Alliance use this system, so it's a decent enough one. The main problem here is trying to draw a line with MMF (without collision detection).
> My chosen approach was to set every location on the map as a 'tile'. At the start of the map, the game remembers which 'tiles' cover is in. Then, upon shooting a bullet, the game only checks the objects in tiles passed through. It's a little more work since I'd have to set up a tile-based system. But the advantage there is that I could just apply it to a tile based pathfinding system as well, since the obstacles will be mapped out too.
|
|
|
Is this worth a look? Let others know! Favourite
|