• they/it/any

en/de
24
amateur math student
professional slash shipper and shitchoster
average math/programming/game dev enjoyer
proud parent of @JWST-live
asks always welcome :3
mutuals, feel free to dm on discord
might reblog light nsfw, be warned
NerdTests.com says I'm a Highly Dorky High Nerd.  Click here to take the Nerd Test, get geeky images and jokes, and write on the nerd forum!



erysdren
@erysdren

hi indie devs of cohost, i've been toying with this dinky little 6DOF space shooter game prototype for the last few days, and i have a cool baseline for the effects, movement and graphics but i have no idea how to write the enemy behaviour code to get satisfying / "engaging" combat... anyone have any advice or a starting point for writing this kind of code? i've never been good at writing NPC behaviour and i have no idea what kind of things i need to consider. thank you!


blaurascon
@blaurascon
This page's posts are visible only to users who are logged in.

You must log in to comment.

in reply to @erysdren's post:

Never really did this in three dimensions so unfortunately I don't have exact advice on how to properly code this, but here are some ideas about enemies, or how to approach this stuff:

I think the first bit might be to ask yourself what exactly you want from the combat.

One thing you can do is boot up a similar game and just try and pay attention to what exactly the enemies are doing. Stuff like when they attack, how they move around, how aggressive they are and so on.

Another thing that might help is to look at 2d twin-stick shooters and see what kind of enemies these tend to have, since there's a good degree of overlap between these kinds of games. Obviously it's not a perfect fit, but it might again be a good place to get some ideas.

The last thing that might help with finding a good starting off point is just build an enemy that chases down the player and doesn't do anything else. Once you've managed to get this thing working, you can start adding some variation. Maybe one enemy chases the player down, but stops at specific instance, another one could chase them, but retreat after they got attacked?

Also seeing that big ship in your gif makes me think about just focusing on capital ship combat instead? That way you can kind of concentrate more on creating specific projectile patterns that players have to avoid?

I would start with a very simple EnemyController script that can handle all the basic actions enemies might do. Things like LookAt, Move (maybe a few versions to move in global space, move in local space, move relative to the player etc.), Fire, AltFire, whatever

Then an EnemyStateMachine script to determine what the enemy is doing right now and send the appropriate commands to the EnemyController. If you're not familiar with how to make state machines, now is a good time to dive in. The most brutal way is a state enum value that you switch on inside the update loop, but it's a good opportunity to play around with data-as-code ideas like executing commands from text files or Unity ScriptableObjects. Basic states might be Idle, MovingTowardsPlayer, AttackingPlayer, Retreating. You might switch between these states based on the enemy's distance from the player and the enemy's remaining health. You can get really fine-grained with it and explore ideas like hierarchical state machines if that serves the game you're making.

That's the basics. Low-level controller to do basic actions and a state machine for a brain.

Additional ideas: A SquadController and SquadStateMachine (instead of an EnemyStateMachine) to have multiple enemies move & fire in formation. A global(ish) singleton(ish) EnemyDirector to do stuff like limit how many enemies will target the player at any given time (ex. Part of moving from Idle state to MovingTowardsPlayer state could be that EnemyDirector.EngagedEnemyCount is below some threshold).

This won't automatically make the combat satisfying / "engaging" since that's a much broader design problem, but it's a good set of modular basic tools that you can use to start tackling that design problem. I think. idk I just spent 3 years working on a narrative game with no combat so take this with a grain of salt haha

make sure your enemy reacts to all sorts of things other than the player, especially other enemies if you can. any swarm of even simple behavior where each thing can communicate a little can get really good quite quickly.

if you're trying to make your enemies smart, don't make them all as smart as you can, make each individual slightly dumber or worse in a different way just to vary up the interactions. maybe some often take worse routes to get to places, or some are way too aggressive and get themself killed, or some try to juke and dodge so much that they can't even really aim. i mainly play fps games i don't know what would apply to a 6dof space shooter

I've only done a lot of enemy design/programming in 2D platformers but this should carry over to a space shooter. A lot of enemy behaviour can basically be boiled down to warning -> attack -> cooldown.

The warning is giving the player some indication that the enemy is about to attack. Its length usually depends on the difficulty (however sometimes a warning can be overly long to mess with the player). For example, if an enemy is about to charge at the player it might flash a bit before doing that.

The attack is... well the attack! Maybe the enemy is charging or shooting at the player. The length can also depend on the attack. An enemy shooting waves of bullets over intervals will be a longer attack than just charging at the player.

The cooldown is right after the attack to give the player a break before the enemy moves onto attacking again. Again, the length depends on difficulty!

Maybe you've made two different enemy types called Enemy A and Enemy B that each have their own attack. You could expose the player to those two enemies separately at first so they learn what to expect. But later the player may encounter A and B at the same time for a different challenge as those two attacks layer on top of each other. A lot of enemy design is basically just designing separate attacks and then layering them in unique ways. Boss design is like that too.

I hope that helps!! Good luck on your game. :D

I've been binging a bunch of 6DOF shooters ever since Descent 3 got a modern port, and you can't go wrong studying enemy behaviors from that series. The franchise even covers both 6DOF shooters and space sims, and the Descent and Freespace series are considered the gold standard in their respective genres. For more recent examples, Desecrators has a truly fearsome cast of foes that all behave differently, and Zerograve implements more bullet hell style attack patterns for its enemies that require a full understanding of how player movement works.

If I had to give more general advice, create a baseline enemy, maybe a wimpy craft that lazily chases the player, then think of interesting ways you could change their AI to get the player to behave in specific ways. Enemies that don't move, like turrets, can even be tweaked in this way. For example, you could make one turret deadly precise but another one lazy. Melee enemies can be especially deadly in games like this, too, as they have free reign to move around and corner players in tight spaces, so don't be afraid to come up with novel encounters!

EDIT:
It should be noted the source code for all the Descent series is open and available! I can't say how useful it is given the platforms and times they were developed for, but that might be something worth looking into.