Search Unity

Need Design Help with Ability System

Discussion in 'Scripting' started by SynergiAios, Apr 20, 2017.

  1. SynergiAios

    SynergiAios

    Joined:
    Feb 3, 2015
    Posts:
    35
    I have created a Ability system for my game to handle easily different root motion changes and all the stuff that is neede to be considered when an ability is activated and stopped. All is working fine except that I run into a design problem I don't know how to solve currently.

    I also want movement to be an ability. And not just movement, I want that the ability to walk forward, backwards, strafe left/right is all a different ability. That is easily made in the first, BUT:

    As I want to have real movement, diagonal movement isn't allowed to be faster then forward or strafe. So If the player strafe's and move forward they both acumulate and the player get's faster. To stop this happening I have to normalize the movement vector before applying as a change. But to normalize I need a movement vector that contains all movements.

    But with my ability system each movement type is his own ability and thus has it's own update function and changes the transform on it's own.

    So what would you guys say how I can handle this?

    I want to stay with my ability system and that each movement type is a different ability. Any ideas on how to still normalize the movement?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I'd say to create - in addition to the movement "ability" - a WalkManager class. Each movement ability reports to the WalkManager the direction it "wants" to go, and the WalkManager then works out which way and how far to move based on those inputs.
     
  3. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    452
    A more generalized approach is to consider the concept of composite abilities. Any single given ability may want to be a part of a larger ability, which can selectively override the behavior of its children abilities.
     
  4. SynergiAios

    SynergiAios

    Joined:
    Feb 3, 2015
    Posts:
    35
    Thank you I really like both ways. I will think about and see then what to choose but both are good workarounds thx
     
  5. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    You could add all of your movement type abilities to a movement List<>.
    (Or create a Movement Interface, so you could iterate through your main Ability list looking for Movement instances)
    Each movement ability would have a Direction vector attribute.
    Then on Update, iterate through the list, adding up all of the vectors, then normalize the finally tally.
     
  6. SynergiAios

    SynergiAios

    Joined:
    Feb 3, 2015
    Posts:
    35
    To Inform on how I solved it, each Ability has a reference to the CharacterController that is associated the playerObject. I have my custom character controller, and to apply the movement is part of the characterController. So the abilities only apply the direction to the character controller and the controller then normalize's and moves the player object.