Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Imagine the char below, a Spartan that in his turn attacks and in the opponent turn tris to block. What would be the logic behind the block process? I just don't want to rely generating random numbers to decide

enter image description here


This is what I want to do, depending of the kind of the shield it would be more likely to block than others:

enter image description here

share|improve this question
One way or the other I think you will end up using % chance to block the attack. Which will rely on random numbers. – DogDog Nov 19 '12 at 19:15
"Tries to block" implies won't always block, which means random numbers due to a chance to block. Otherwise you can have it always block, and reduce damage by a set % (possibly based on stats). What's your aversion to random numbers? – Orin MacGregor Nov 19 '12 at 19:22
Then what would you want to decide it? The stats of the players? If the defending player is human, would you want him pressing a button quick enough? – tyjkenn Nov 19 '12 at 19:23
After your update, it sounds like all you need is a stat coming form the shield that contributes to blocking. Say a small shield adds 10%, medium adds 25% and large adds 50%. – Orin MacGregor Nov 19 '12 at 19:58
Excellent drawings btw. – wardd Nov 20 '12 at 22:45
up vote 3 down vote accepted

The easiest way to cause this effect would be to give each shield type a % chance to block (possibly also influenced by other stats, depending on how you want the logic to function)

Say if a small shield blocks 10%, a medium shield blocks 25% and a large shield blocks 50%, like in Orin's comment. At this point you just need to grab a random value and see if it's less than whatever your block value is.

Easy way is to grab a value between 0 and 1 (many random value generators will give you this, if not divide by max possible value and you have it anyway), then compare with the appropriate percentage (10% is 0.1, 25% is 0.25, ...etc). If the random value is greater than or equal to the shield value it's a hit, otherwise it was blocked

If you wish to add a character stat, terrain, direction, or anything else to this calculation, simply decide how it adds or subtracts to the block % and then do the comparison as normal. Values less than or equal to 0 will never block and values greater than 1 will always block, though you can modify this behavior by setting limits on the value.

share|improve this answer

I don't know the combat system you are using or are trying to make (how you define it etc.)

I'll try to give you a solution from a game called Runescape. You have 3 basic meele combat skills:

Attack - defines how often you will break through / makes the average hit higher

Strength - defines the highest possible hit

Defence - defines how much less you will get hit

The weapons you use have three types of "stat bonuses"

Attack bonuses - for eg. your sword has +100 slash but just +30 to crush

Strength bonus in your wep. will define the max hit that you be able to hit (more than with fists or worse weps.)

Defence will be for eg. +120 dmg resistance to slash but only +10 dmg resistance to crush.

When you get slashed with that wep. you take the slash stats of the wep and you add +100 to -120 you will find out that you have 20 damage resistance from slash, then using your combat algorythms you can define that the average hit you get when slashed will be low because your armor is better than the attackers atk stats.

When you get crushed you add -10 to 30 and you get that your opponent will have +20 dmg exceeding your armor. And that way the average hits you get will be higher

If I wrote something unclearl please correct and comment to ask additional questions

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.