• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Design Chance To Kill

B

bte_lead

Guest
Right now, I am using this script to determine whether a character in a xcom-like RTS will be able to hit their target.
Code:
/// @function scrCalculateHitChance()
/// @description Returns the chance that the soldier will hit
/// @params Soldier
var s = argument0;
var distance = point_distance(s.x, s.y, s.target.x, s.target.y);
if(s.crouch){
    distance = distance * (3/4);   
}
if(200/distance * 100 < 99){
    return 200/distance * 100;
}
else{
    return 99;
}
However, it doesn't work as I intended. The distance seems wonky, (the soldier can be a few pixels away with a 17% chance) and I am not sure what to do with the crouch modifier.
How would you improve/write this code?
Thanks
Ian
 

Simon Gust

Member
1st this should be in the programming section.
2nd 17% chance is actually what you'd have in xcom at that range.
The math is correct as far as I can tell.
But the target / soldier might not be the correct one.
How do you determine the target / soldier?
 

Yal

šŸ§ *penguin noises*
GMC Elder
How about something like this? Lerp is the goto function when it comes to interpolation, you should try to keep your own maths to a minimum and things get harder to screw up. :p
Code:
var s = argument0;
var distance = point_distance(s.x, s.y, s.target.x, s.target.y);
if(s.crouch){
   distance = distance * (3/4);   
}
maxdistance = 512;
return clamp(lerp(0,100,(maxdistance - distance)/maxdistance),0,99);
Also, why is the user an argument while the target isn't?
 
Top