1
\$\begingroup\$

So I'm making a simple RPG game and I'm currently stuck on creating an attacking module for it.

I need to create a simple attack algorithm but I'm really not very good at it.

Each character has 3 base states - Attack, Defense, Dexterity

and all characters start off with 50hp and they gain 5hp per level.

What formula should I use to determine chance of hit, and how much damage is dealt? It doesn't have to to too overly complex. Just something simple for now.

\$\endgroup\$
4
  • \$\begingroup\$ You should mention what you have tried, or the research you have done and why those methods won't work with what you need, other then that is is entirely opinion based as someone could suggest you don't need hit chance at all, and if you want a simple system you could just do attack - defense for damage, and leave dexterity completely out of it. \$\endgroup\$ Commented Aug 24, 2017 at 16:16
  • 2
    \$\begingroup\$ Like any game feature, in order to choose a good formula for attack resolution, we need to know what criteria or goals it's trying to meet. Otherwise it's impossible to pick out any one formula as "suitable" out of the countless possible options. Try working through some example scenarios that you think will arise in your game, like "My main character fighting a common enemy in the first half-hour of play would have these stats..." then describe what outcomes you hope to see in each scenario, or what outcomes you want to avoid/minimize. \$\endgroup\$ Commented Aug 24, 2017 at 16:41
  • 1
    \$\begingroup\$ I would advise "borrowing" from a known game to start with. Do you want something more in line with D&D or say Final Fantasy 7? If you hone your question down to a case study I think you can get better answers as this question is extremely broad. \$\endgroup\$ Commented Aug 24, 2017 at 18:20
  • \$\begingroup\$ It's all up to you to decide. If the game is still in development stage, I recommend you to use plain attack damage: hp -= attack. Improve it later on when you have a playable version \$\endgroup\$ Commented Oct 4, 2017 at 5:27

1 Answer 1

0
\$\begingroup\$

I'm going to give you my own, it may not be the right one as its rather subjective to what your looking for.

Attack will be the amount of damage done per tick / turn or individual attack. Dexterity will be considered the speed of the character in this instance. Defense we will subtract from the enemies attack with some random variation.

So for example

npc1.attacktimer = 0

game_loop/action loop ()
{
  npc1.attacktimer += frame_time;
  if (npc1.attacktimer >= 10.00 / dexterity)
  {
  //attack
  npc2.health-= npc1.strength - (npc2.defense / 2 + rand(6)) // randon number between 1 & 6 
   npc1.attacktimer = 0;
  if npc2.health <= 0 
   {
    npc1.exp + 5;
   }

  }



}

This is a very general example, pseudocode, I'd suggest however setting up a message handling interface or a interaction interface further down the line though thats semi off topic.

Where you check other conditions, example.

npc1 control loop(current targets)
{
 //checks whether combat is valid, then applies damage calculation.
 combathandler.attack(me, target)

}
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.