Hello, I’m working on a ball game but the jumping system is very slugish and delayed.
What can I do to make it more smooth?
Code:
local hum: Humanoid = char:FindFirstChild("Humanoid")
local ball = char:FindFirstChild("Ball")
local canJump = true
local debounce = false
local lastJumpTime = 0
local cooldownTime = 4
if ball then
if not canJump or debounce then
return
end
-- Perform raycasting to check if the ball is on the ground
local rayStart = ball.Position
local rayDir = Vector3.new(0, -1, 0)
local rayLength = 5
local hit, hitPosition = workspace:FindPartOnRayWithIgnoreList(Ray.new(rayStart, rayDir * rayLength), {ball, unpack(char:GetDescendants())})
if not hit then
return -- Ball is not on the ground, cannot jump
end
SetValue(onAir, true)
canJump = false
debounce = true
local Velocity = Instance.new("BodyVelocity")
Velocity.Parent = ball
Velocity.MaxForce = Vector3.new(0, math.huge, 0)
Velocity.Velocity = Vector3.new(0, 35, 0)
Velocity.P = 100000
task.wait(0.5)
SetValue(onAir, false)
task.wait(cooldownTime) -- Cooldown time before allowing the next jump
canJump = true
debounce = false
else
return warn("Ball not found")
end```