Math for accuracy statistic?

Get help using Construct 2

Post » Sun Jan 15, 2017 8:01 pm

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
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Mon Jan 16, 2017 1:30 pm

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%.
B
5
S
3
Posts: 194
Reputation: 1,065

Post » Mon Jan 16, 2017 4:18 pm

Hi!

Thanks, that did the trick. I now have:

Code: Select all
Every tick - Set value of variable 'Accuracy' to (100/ShotsFired)*ShotsHit


That should be it right?

Thanks again for your help!

- R
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Mon Jan 16, 2017 4:56 pm

Rudi55 wrote:Hi!

Thanks, that did the trick. I now have:

Code: Select all
Every tick - Set value of variable 'Accuracy' to (100/ShotsFired)*ShotsHit


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).
Image Image iTunes: Match3 | Google Play: Match3
B
109
S
39
G
31
Posts: 1,175
Reputation: 29,314


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 22 guests