Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Enemy AI attacking

Discussion in 'Game Design' started by tameezameer07, Mar 6, 2018.

  1. tameezameer07

    tameezameer07

    Joined:
    Mar 6, 2018
    Posts:
    1
    I'm a beginning game designer and I'm trying to design a combo based Fighting game. How would I code the enemies to select which combo to perform? I want to leave it up to RNG but I don't know how to program that.
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    6,527
    Vryken, carking1996 and theANMATOR2b like this.
  3. fetish

    fetish

    Joined:
    Aug 25, 2015
    Posts:
    66
    For others:

    I did this for a MUD I worked on back in the day. Essentially, try to figure out how useful an ability/spell/combo/whatever might be, build a weighted list, and work from there.

    essentially, each spell (in this case) had an int properUse() function, that would return a number based on how suitable the spell was. If it was an AOE spell, for example, it'd take the number of valid targets and square it to return the value (it was more complex than this, it can be as complex as you like, all that matters is that you pump out a number that gives an idea, relatively speaking, how likely the AI is to use the spell.

    in C#, I'd probably use a dictionary of type List<Ability, int> for this purpose. Once I'd populated it with each ability and it's use potential (the int in the dictionary), I then loop through and sum all those values, and pick a random number between 0 and that range.

    Then you loop through the dictionary again, subtracting out the weighted value of that ability from your randomly generated number. When that int is <= 0, then trigger the current ability you're processing through the dictionary. No sorting or ordering is necessary.
     
    Doug_B likes this.
  4. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    519
    If this was stackoverflow 90% of threads would be marked as duplicate and closed within minutes.
    And Erric would have 90% of all reputation on the site.
     
    carking1996 and Martin_H like this.
unityunity