I’m working on a game with combat similar to dark souls and right now my AI is only making combat decisioubs based on distance to the player. I want to add in some more variety and make the AI more intelligent, but I’m not sure where to start. I thought about making a randomizing bool by adding a flip flop on a timer and using that to drive some decisions in my behavior tree, but other than that I don’t know. What are some common variables or any other input y’all would have on setting up melee combat.
Well you could branch out depending on what the players class is (I would kill rangers very different then other warriors) Also health remaining (both self and player) Also maybe do it by time of day, maybe at night they fight differently than in the morning.
Hi Mcgillchris,
Few quick thoughts:
- The AI could check the movement speed or turn rate of the player. If the player moves slow or turns at a slow rate, then the AI could adapt and try and fight faster with a lot of movement?
- Weapon type. On the same tune as King Scott above, you would fight an agile archer very differently from how you might fight a armor clad knight.
- Location. The fighting styles may differ depending on where a fight is taking place, for example fighting in a small corrider will be different from fighting on an open plain.
I have my AIs pick a vector relative to the player’s position and orientation and move to it before moving in to attack; this works well if your game will feature multiple enemies attacking the player at once, since they will fan out around the player and attack from multiple sides, rather than charging head-on at him.
I do things a little bit differently because I don’t allow the RNG to touch my AI behavior (no blaming RNGesus for your failure in my game), but one thing you should definitely do is a weighted randomization of the actual melee attack. For my characters, which attack they use is driven by things like distance to the player when the attack logic is executed and how many other enemies are within melee distance of the player, but RNG would work as well.
I would also have enemies behave differently when their HP is low (maybe a weighted random that changes weight based on HP? i.e. at 100% HP, always attack, at 0% HP always block/evade, so current HP% determines the likelihood of a defensive vs offensive maneuver.
@kingscott Good thought! I hadn’t even considered time of day, and health would be good too.
@connorthescot thanks for the input. I really like the location based idea. This is gonna get complicated haha. Do y’all usually draw your behavior tree out on paper before building it in game to plan it out, or do you just build what you think of and then fiddle around to make it better?
@rhythmscript awesome! How would you go about getting a random vector relative to the player location? That seems like a really good idea. Also what do you mean by weighted randomization? I think I follow but I’m not 100%. Thanks!
Another thought is weapon usage. In my game, certain weapons/equipment will have better capabilities than others depending on your opponent’s equipment. For example, a shield will be very good at defending against piercing attacks, and less so at slashing attacks, so if my AI has a spear (which can do both types of attacks) and it comes upon a player with a shield equipped, it will favor slashing attacks.
I had another idea. Aggressiveness based on how much gold the guy has. As I for one would always attack a person if he had more gold then he knows what to do with, not so much if he only has a penny.