Fokker Dr1 Added
The Red Barron!
In the 1.3 update of Mech's take the Somme I added aircraft to the battle. You now need to watch out for Fokker Dr1 triplanes made famous by the Red Barron that attempt to bomb and strafe your mech. This addition really shifts the balance of power further towards the enemy, as while the aircraft don't hit you very often they do keep you distracted making it easier to be picked off by the soldiers.
For the aircraft movement and AI I deliberately kept things simple and steered away from any kind of physics based movement for the aircraft as that has proved challenging in the past, especially in combination with AI. Instead I've gone for a really simple state machine and lerping vectors for movement. The state machine is nothing more than an enum and a switch statement, much simpler than I would normally do but given that this started as a game jam game I didn't want to over engineer the solution. Here's the contents of the update method containing the state machine logic, as you can see there's not much to it.
{
case AircraftState.Navigating:
DoNavigatingState();
break;
case AircraftState.Chasing:
DoChasingState();
break;
case AircraftState.Bombing:
DoBombingState();
break;
case AircraftState.Strafing:
DoStrafingState();
break;
case AircraftState.Climbing:
DoClimbingState();
break;
case AircraftState.Crashing:
DoCrashingState();
break;
case AircraftState.Destroyed:
DoDestroyedState();
break;
}
Movement is very simple, turning is done by simply lerping between the aircraft's forward vector and the destination vector:
{
var direction = (destination - transform.position).normalized;
transform.forward = Vector3.Lerp(transform.forward, direction, _turnSpeed * Time.deltaTime);
}
Once you're facing the right direction it's simply a case of translating the aircraft's position:
The AI is just as simple, pick a random point around the player, fly there, then fly towards the player dropping a bomb at a configured distance from the player. This repeats while the aircraft has bombs, then it switches to strafing which is basically the same process except the plane dives, strafes, and climbs away instead of dropping a bomb.
Currently there's no object avoidance in the AI, it basically assumes that there's nothing in the way and it can just fly in a straight line to the target. For this game that doesn't matter too much as there aren't any tall buildings or mountains but if I did want to factor these kinds of things in then I'd probably need to switch to a more complex state machine to break up the logic further and avoid one really long class file.
One of the things I've learned over the last few years is to not worry about building a perfect solution, just build something good enough for your use case, and don't be afraid to define limitations to simplify development. My theory is that it's better to finish a game than spend weeks or months building one small part perfectly only to lose motivation to finish the game. All up I think the aircraft model took about 2-3 hours to create, and the Unity setup and AI took 3-4 hours to get running which works out quite well when I'm just working 1-2 hours in an evening.
Free Models?
As part of building games I'm starting to get quite a collection of 3d assets I've created and I'm wondering if anyone would want them for their own projects. If you are interested let me know in the comments below and I'll upload them.
Files
Get Mech's take the Somme
Mech's take the Somme
Storm the famous WW1 battlefield in a giant Mech!
More posts
- New machine gunner enemyOct 19, 2021
- Mech Jam 2 PostmortemOct 07, 2021
Leave a comment
Log in with itch.io to leave a comment.