Snayff / nqp3

1 stars 2 forks source link

Base for Unit AI #46

Closed eh-jogos closed 1 year ago

eh-jogos commented 1 year ago

Video of results:

https://github.com/Snayff/nqp3/assets/13070158/bffa61ca-06e4-40c2-9877-e13e56dd2838

Overview

This implements #29 partially.

It focuses on creating a basic infra structure to develop Unit AI on top of it and a base for creating visualizations that help debug Unit AI behavior.

Some folders got reorganized so that Units can have their own state machines and states, and factory/ref_data knows where to get them.

There are currently two AI states implemented:

Visualizations options

On the scene unit.tscn there's a new node called DebugVisuals. It only works on builds that have the "debug" feature, so either the editor or builds exported with debug. On "release" builds it automatically removes itself.

What it draws and how it draws can be configured in the editor's inspector. image

Other Notes

There's a big TODO on the way the actors are choosing their targets, its in the code and across some of the commit messages, but repeating it here:

I'm currently limiting so that actors only target enemy targets from the designated unit, or ally targets from any ally unit. This is to stop actors just targeting the exact same actor and getting jumbled up and blocking one another, or ate least improve it a bit.

The way it works now the actor asks its target unit for an "available" actor, and the unit will choose the first actor with less targets on its back.

I don't think I'm doing it in the best place or way, because we are filtering actors by preference and then asking the target's unit for a valid actor, so basically we're changing the target after filtering for preferences. I think ideally, we should refactor the preference filter to find a valid unit, not a valid actor.

So it should be the "nearest" unit, or attacking "unit", or most damaged "unit" and then ask the unit for a valid actor. But it was a bigger refactor and time was running out so I did it like this for now and left this refactor for later.

Snayff commented 1 year ago

I love the debug visuals and approach, great work.

As I mentioned on Discord, I think Actors should target based on proximity and their own preferences, regardless of clumping. The dog piling is part of the fun!