Math for accuracy statistic?

0 favourites
  • 4 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • Hello,

    I'm trying to figure out how to make an accuracy statistic at the end of the game.

    The player can fire a bullet with spacebar.

    I'm not sure how to do this. Math is my achilles' heel.

    The bullet can hit (an enemy) or miss (bullet goes outside screen).

    If anyone could help me out that'd be much appreciated.

    Regards - R

  • Just count the fired bullets and the bullets that hit. Then you need to calculate the percentage of the bullets that hit. For example if the player shoots 99 bullets and 33 of them hit the target:

    (100/99)*33=33.33%

    So in this case the accuracy should be 33.33%.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi!

    Thanks, that did the trick. I now have:

    Every tick - Set value of variable 'Accuracy' to (100/ShotsFired)*ShotsHit[/code:7m75tmpo]
    
    That should be it right?
    
    Thanks again for your help!
    
    [ul]
    	[li]R[/li]
    [/ul]
  • Hi!

    Thanks, that did the trick. I now have:

    Every tick - Set value of variable 'Accuracy' to (100/ShotsFired)*ShotsHit[/code:1n9b8ckm]
    
    That should be it right?
    
    Thanks again for your help!
    
    - R
    

    Hi,

    I wouldn't use "Every tick" in this case.

    Just add on every shot "1" to "shotsFired" and "1" to "shotsHit", if the bullet hits the enemy.

    Whenever one of those values changes, call a function to calculate the accuracy.

    For instance,

    shotsFired = 10;

    shotsHit = 1;

    Accuracy = 10; //10 %

    On "bullet" collides with "enemy"

    -> Add 1 to "shotsHit" (makes it 2);

    -> Call Function "calcAccuracy";

    On "bullet" created

    -> Add 1 to "shotsFired" (makes it 11);

    -> Call Function "calcAccuracy";

    On function "calcAccuracy"

    -> Set Accuarcy "shotsHit > 0 ? 100/shotsFired * shotsHit : 0" //Short-if -> ("CONDITION ? TRUE : FALSE")

    If the player has 0 shots fired and the function gets called, it would devide by 0 (that's whay there is the short-if to avoid that).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)