Make or miss percentage

For my shooting system in my basketball game, I need to create an equation that takes all factors into consideration for whether you make or miss a shot. I’m having trouble with getting a percentage from 0 - 100 using the players shooting attribute (0 - 100), distance from the basketball hoop, and shot timing. If anyone could help me form an equation using these factors, it would really help me. Thanks, and if you need more info please ask.

3 Likes

If you’re trying to make a percentage from a numerator and a denominator you can just do
math.floor(numerator/denominator*100)

1 Like

Im terrible at explaining, but Im basically trying to get a percentage from the players shooting attribute, for example 80, and their distance from the hoop, and how well they timed a shot. To determine whether they make a shot or miss it

1 Like

From what I’m understand you’re taking multiple variables into account when calculating for a “shot chance” percentage, if that’s the case you would have to make your own formula to determine the probability of your player’s chance of scoring.

This differs on how you want it to act in your game but how I would approach it would be:

  • Find skill shot chance (let’s say their shooting skill is at 40)
  • Find distance to net (a number that ranges from 1 to 30, let’s do 15)
  • Well-timed shot (a number that ranged from 0 to 10, let’s say 10)

let’s say that your game made it so that a shooter with a skill of 100 will be able to make a basket at any distance with a 100% chance of making a basket, in this case, the shooter’s skill is at 40, let’s also say that the player is at the 3 point mark with a distance multiplier of 15, and this player perfectly timed their shot.

My formula would be then Chance = A - B + C, which would be Chance = 40 - 15 + 10 = 35, the player would have a 35% chance of making a well-timed 3-pointer as a 40 skilled shooter, which sounds about right to me.

I’m not exactly sure of what you’re looking for but this is how I would approach this problem.

1 Like

Alright thank you, this gives me a basis to work off of. I’m going to try it out. again, thank you so much!!!

Being able to make a shot 100% of the time is impossible, so I think if you cap the percent at something like 90% it would be more realistic.

Yes, I was planning on capping it at different values depending on their build. Thanks for the tip!

Edit: just realized you didnt reply to me.

well yes, that’s why I said these variables are dependent on the type of game you’re making- but having a variable with an impossible shot chance also allows for funny stuff- or debugging if need be.

I made this function that somewhat realistically simulates the percentage:

function CalcPercent(Skill, Distance, TimeReleased)
	local TimeToRelease = Distance ^ .1
	local Percent = math.clamp(math.floor((Skill) - (Distance / 2) - math.abs(TimeToRelease - TimeReleased)), 1, 90)
	local Chance = Percent / 100
	return Chance
end

local Chance = CalcPercent(80, 10, 1.5) -- First param = Skill. Second = Distance from goal (in studs). Third = Time shoot button was held

if math.random() <= Chance then
	print("Made shot")
else
	print("Didn't make shot")
end

I’ll try this out as well when I get home. Thank you, this looks very well thought out.

1 Like