Jump to content

Recommended Posts

Hey,

 

can anyone give me examples how are the scripts for fighting written in unity or pillars or baldurs gate or other games you know for example?

Any tips on language and things like that?

Is it possible to write a 'fighting script' for an character with threads in c# (not in pillars but lets say in my own game) or what else is used for such things?

 

 

Link to comment
Share on other sites

AI in video games is a complex subject, and its implementation depends entirely on what sort of game systems you're using. It's difficult to talk about it in broad strokes.

 

In an IE-style game like PoE, the AI is usually broken down into a series of potential actions. A monster, for example, might have two actions that it can perform:

 

-Move to a target and perform a melee attack.

-Cast a healing spell if I am below 50% HP.

 

These actions all have a series of conditions that must be fulfilled before that action has the potential to be chosen. Moving to a target requires that the monster is able to move (they do not have a status effect that restricts their movement), that they are able to find a reasonable path to the target (using A* or something similar), and, in the case of PoE, that the monster is not engaged. You can set these conditions to either be absolute (they must be true for this action to be considered) or variable (e.g., even if I am engaged, there's a 20% chance that I will choose to break engagement if the other conditions are true).

 

Once the AI runs through its potential actions, it compiles a list of valid actions that are then "weighted." What this means is that monsters will generally choose to perform certain actions over others if that action is a valid choice. In the case of the example monster above, casting a healing spell at 50% is given a high weighting, while using a melee attack is given a low weighting. This means that, if the conditions for casting a healing spell are met, the AI will almost always try to cast a healing spell over using a melee attack. Weightings don't have to be absolute, so you can still have a variable chance of the AI using different abilities during combat, assuming all of the conditions for every action are met.

 

Once the action is chosen, it's carried out by the AI. After being carried out, the AI then selects another action using the above process. It's important that the AI is checked semi-regularly to ensure that it actually is able to perform its currently-queued action, or else you may end up with a case where the AI has an action queued, is suddenly prevented from performing that action (such as their previously-accessible path becoming blocked), and therefore has no more actions to run and merely sits there dumbly.

Edited by Anthony Stark
Link to comment
Share on other sites

AI in video games is a complex subject, and its implementation depends entirely on what sort of game systems you're using. It's difficult to talk about it in broad strokes.

 

In an IE-style game like PoE, the AI is usually broken down into a series of potential actions. A monster, for example, might have two actions that it can perform:

 

-Move to a target and perform a melee attack.

-Cast a healing spell if I am below 50% HP.

 

These actions all have a series of conditions that must be fulfilled before that action has the potential to be chosen. Moving to a target requires that the monster is able to move (they do not have a status effect that restricts their movement), that they are able to find a reasonable path to the target (using A* or something similar), and, in the case of PoE, that the monster is not engaged. You can set these conditions to either be absolute (they must be true for this action to be considered) or variable (e.g., even if I am engaged, there's a 20% chance that I will choose to break engagement if the other conditions are true).

 

Once the AI runs through its potential actions, it compiles a list of valid actions that are then "weighted." What this means is that monsters will generally choose to perform certain actions over others if that action is a valid choice. In the case of the example monster above, casting a healing spell at 50% is given a high weighting, while using a melee attack is given a low weighting. This means that, if the conditions for casting a healing spell are met, the AI will almost always try to cast a healing spell over using a melee attack. Weightings don't have to be absolute, so you can still have a variable chance of the AI using different abilities during combat, assuming all of the conditions for every action are met.

 

Once the action is chosen, it's carried out by the AI. After being carried out, the AI then selects another action using the above process. It's important that the AI is checked semi-regularly to ensure that it actually is able to perform its currently-queued action, or else you may end up with a case where the AI has an action queued, is suddenly prevented from performing that action (such as their previously-accessible path becoming blocked), and therefore has no more actions to run and merely sits there dumbly.

Thank you, that gave me a nice idea for some basic algorithms like;

 

timer = 60 ms

each 1ms timer = timer - 1

if timer = 0 

choose new action, set timer = 60 ms

 

thread 1:

while(1)

{

timer = 60 ms

while(1)

{

time.idle(1ms)

timer = --1

end

}

if timer == 0

time.new_action_for_all_objects()

end

}

 

thread 2:

while(new_turn)

{

object.perform_action()

function perform_action:

{

switch conditions_table (int []):

case [0,0,1,0,-1,50%,0,0]:

object.attack(target)

case [0,0,0,0,0,10%,1,1]:

object.heal(object)

end

}

}

end

 

this is actually heading towards easier implementation than i originally though, you gave me nice insight into the topic, really big thanks!

Link to comment
Share on other sites

Baldur's Gate scripting is a well trod subject; if you search for scripting references there are plenty around. 

 

AI is non-trivial in that it relies heavily on support systems. It assumes that there's a pathfinding system so you can find your way to your target. For that matter, it assumes you have a targeting system. But if you've got a way to target other guys, get to them and perform actions on them, you've got a good base.

 

The algorithm you've outlined is simple, and it'll work, but it assumes that you don't need to change your mind in the middle of an action, etc. I suspect as you go you'll find all the pitfalls and edgecases that are annoying. But throwing yourself into it is a good way to go--good luck!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...