Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Bob423

Hit detection formula

Question

I'm trying to make a custom accuracy formula, but I'm having some problems.

For the damage formula I used formulas from commercial games like Disgaea 4 as a reference, but the only thing I can find about accuracy is unhelpful things like "hit chance = 1.2 * (HIT/SPD)" I don't know how to put that into my game at all.

 

Also, I'm confused as to why, in the code, there needs to be a first and second hit detection.

Everything seems to work fine when I only use the first one, which comes before the damage formula

The first hit detection looks like this:

hit_result = (rand(100) < attacker.hit)

which i think means, take a random number between 0 and 100. if it is greater than the attacker's hit, then hit_result = true.

 

and then there's this silly thing, which comes after the damage formula:

# Second hit detection
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)

What are the colons and question marks for?

I don't get it >.<

 

For critical hits it's easy since I just keep the LUK stat between 0 and 100, but the HIT and SPD stats can be from 1 to 255

Maybe I should use an evasion stat so battlers can attack often, but be easy to hit...

Edited by Bob423

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

I may be wrong here, but here's what I think is happening.

the 'hit' variable holds the chance to hit, in percents.

first it's set to the skill's hit chance, then the attacker's hit stat is factored in. then RMXP randomly decides if the attack hit, based on the hit-percent. this is a temporary/partial check.

if this initial check results in the attack missing- it misses. but if it results in hitting, other factors are used to decide if the attack hits. so the attack may still miss, depending on the other factors, which are:

hit = self.damage < 0 ? 100 : 100 - eva
factor 1: is the damage negative

I think healing skills use 'negative' values. looks like RMXP makes healing skills always hit (hit= 100)

 

factor 2: the target's evasion

if the damage isn't negative, the chance to hit is set to (100 - target's 'eva'). makes sense: if the target has 10% chance to evade, the chance to hit it is 90%.

 

hit = self.cant_evade? ? 100 : hit
factor 2: can this skill be evaded

if the skill cannot be evaded, the hit chance is set back to 100%

 

hit_result = (rand(100) < hit)

lastly, decide if the skill hit or not, based on the 'hit' percent.

this time it's the FINAL result.

Edited by Metaclaw

Share this post


Link to post
Share on other sites
  • 0

Oooooh I know this one, I think!

 

It's the same in PHP, which I'm totally pro @.

hit = self.damage < 0 ? 100 : 100 - eva

Lemme rewrite this for you in expanded form (in php syntax coz I duno ruby if statements, som imma chuck in some semi colons)

if(self.damage < 0){
   hit = 100 
}else{
   hit = 100 - eva
}

Therefore what we're looking at is a shorthand for an if statement. Simple right? The first one (100) is if the question we're asking is true, and the second (100 - eva) is the value if the question is false. 

Share this post


Link to post
Share on other sites
  • 0

so...

 

if self.damage = 0
hit = 100
else
hit = 100 - eva

that's sorta simple i guess, but I still have no idea what good this does lol

Thanks anyway :D

Share this post


Link to post
Share on other sites
  • 0

Thanks, that helps a lot! :D

Guess I don't really need to change it then :P

And now I know what I'm doing when I change the EVA stat :D

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...