In my basketball game, Based on your timing and other factors, you will miss or make a shot. I am already getting the percentage (0-1) of all the factors but how can I actually apply this to the projectiles end position. I feel like my current system kind of sucks.
well what is your current system?
I just add a vector with the percentage on the x and z axis to the end position.
i would just get this position then form a velocity vector to it where that is (offset - player).Unit
I’ve got that part down, but my struggle is when if you time the shot badly then it will effect the end position.
very vague, cant help you then
Ok so basically, I use ego moose’s way of firing projectiles. Ok that works great. But, when you time a shot badly, you get a percentage value based on your timing. So if you time it horribly, we’ll just say you get a percentage of 40 but in decimal form 0.4. How could I apply this to the projectiles desired position to make it possible to miss shots? Hopefully I explained it well enough. I’m not very good at explaining, sorry.
Oh simple, multiply it by the length of 2 bounds
then set that as a offset to the basketball hoop where the min is the z or whatever of the left rim and max is right rim
care to give an example so that I can understand better? If not that’s fine. Thanks a bunch!
I thought that this would be an interesting problem, so I did this myself. I tried to imitate NBA 2K21’s shot meter with the least effort put in to explain this. Basically, I have a gui in the top-left corner that is shown when you press and hold down on LMB and you’ll have 3 seconds to make the timer hit exactly 0. The closer you are to 0, the more accurate the shot will be towards the hoop. The direction of the ball will differ based on whether or not you have passed the 0 mark or you haven’t.
When the tool has been deactivated (LMB released), the ball is shot towards the hoop with a little offset that is based on the percentage of how far you were from the 0 mark (TargetTime):
Tool.Activated:Connect(function()
TargetTime = os.clock() + 3
end)
Tool.Deactivated:Connect(function()
local time_offset = TargetTime - os.clock()
local new_ball = Ball:Clone()
local g = Vector3.new(0, -workspace.Gravity, 0)
local Target = Rim.Position
local x0 = Ball.CFrame * CFrame.new(0, 2, -2)
-- the maximum displacement of the ball would be 10 studs away from the hoop. This is the case when you have passed "TargetTime" by 3 seconds or you've immediately released LMB upon pressing it
local offset = Vector3.new(0, 0, math.clamp(time_offset, -1, 1)) * 10
Target = Target + offset
local t = 1
new_ball.CanCollide = true
new_ball.CFrame = x0
new_ball.Parent = workspace
new_ball:ApplyImpulse( new_ball:GetMass() * ((Target - x0.Position - 0.5 * g * t ^ 2) / t) )
delay(t + 2, function()
new_ball:Destroy()
end)
end)
Video demonstration:
The positioning of the offset may differ based on the orientation of your basket. Hopefully, this should give you some insight on how to do this
Oh my gosh!!! Thank you so much for this. you are truly amazing man.
Edit: I tested it, just changed 10 to 5 for less effect, and it works absolutely perfectly. I really can’t thank you enough!!