Quantcast
Channel: Questions in topic: "unit"
Viewing all articles
Browse latest Browse all 68

Component based architecture Unit, AI, Health, Attack

$
0
0
I've read several articles about component-based programming. It's very difficult for me to make such an component-based architecture, because i'm coming from the OOP site. What i want to achieve: A Unit, that has health, damage, attackRange, detectionRange of enemies etc. This unit spawns and walks to the enemy base. If it detects an enemy, it shall kill the enemy and then continue to walk to enemy base and attack it. Now i created several components: - Unit - has all the attributes like health armor, damage,... - Health - Reduces the health - Detection - detects enemies with the onTriggerEnter function and notifies the AI to change state in attacking/hunting/walking/dying/waiting mode - AI - handles the states and sets the walking destionation with a NavMeshAgent - Attack - attacks, if in attacking mode Now on a first look, they are quiet independent, but then they get connected all together and i receive the opposite of a decoupled architecture. The Attack script calls Detection to get the targeted enemy. The Attack script needs the unit to get all the values like damage and attack range. The Attack Script needs the AI to change the state to WalkingMode after killing an enemy... And this way somehow all scripts are somewhat coupled again and i have to require my script a lot of others: [RequireComponent(typeof(AI),typeof(Unit),typeof(Detection))] It seems for me pretty impossible to realize my intention in a decoupled way. How do you realize decoupling? How would you organize this components? Would you create more components? Would you let it, as it is? What am i doing wrong, that i can't get decoupled components?

Viewing all articles
Browse latest Browse all 68

Trending Articles