doubledamnation icon indicating copy to clipboard operation
doubledamnation copied to clipboard

Remake Enemy Logic

Open TheYellowArchitect opened this issue 1 year ago • 0 comments

It is no secret that the code for the enemies is not well-designed. After all, it was made back in 2018, I didn't even know a design pattern back then. I didn't read on AI either, it was quite literally handmade without any guidance, I still remember the "breakthroughs" and how making the AI felt like exploring, happy times. There are some good things, like the split of enemy onto pathfinder and behaviour, and the attacks being split in classes, hence monsters are "modular" (e.g. hollow with some clicks, could get the jump attack of satyr, or the rush attack of centaur and minotaur)

However! There are 5 horrible things, which linger to this very day, as I didn't know anything about AI, and I was coding whatever came into my head:

  1. Attack Detection Hitbox and Attack Damage Hitbox are MERGED Yes, this is as horrible as it sounds. The same hitbox which says "if in X range, use your first attack" is also the hitbox which checks for applying damage within X range. It isn't really noticeable in-game, because with the above, enemies attack when they get in range of their attack. But it is noticeable for Harpy's spin attack. Harpy's spinattack is clunky/janky, because of this flawed design.

  2. Sidewalled Bug A serious bug, where enemies at wall sides have bugged AI (e.g. they run towards you but cannot move towards you...)

  3. Flying Type Instead of splitting EnemyBehaviour into Grounded and Flying, I slapped Flying code onto default EnemyBehaviour. And if (flying) then bloated code overrides default. Not a bug, not wrong, but it makes the code ugly and bloated.

  4. Delete IDamageable My first experience with Interfaces, and I did it with monsters. Unity is not meant for interfaces, it goes against its component system. And if you override them, you create insane spagghetti.

  5. Decouple State Machine from Physics.velocity Its such a mess. Physics.velocity is set on Update() and pathfinder, and FixedUpdate() This is the only part which is worse than WarriorMovement

For this reason, netcoding enemies was impossible, and I just disabled EnemyBehaviour altogether for the client.

TheYellowArchitect avatar Aug 11 '22 12:08 TheYellowArchitect