Ok so i’ve been making a soccer system with my own physics system for it because bodymovers didnt work great for me, and sometimes the ball just doesnt bounce.
My code:
local BounceAmount = .5
local lastY
local lastVel
game["Run Service"].Heartbeat:Connect(function(dt)
BallPhysicsEnabled = not (BallHolder)
if BallPhysicsEnabled then
local vel:Vector3 = Ball:GetAttribute("Velocity")
local velWithoutY = Vector3.new(vel.X,0,vel.Z)
local fieldPos = field.MainGround.Position.Y+field.MainGround.Size.Y/2
local dist = Ball.Position.Y-fieldPos
local grounded = dist < Ball.Size.Y/2
print("Grounded:", grounded)
print("Distance:", dist)
print("Ball position:", Ball.Position)
print("Ball velocity:", vel)
if grounded then
vel = velWithoutY + Vector3.new(0,-vel.Y*BounceAmount,0)
else
vel -= Vector3.new(0,.005,0)
vel = Vector3.new(vel.X,math.clamp(vel.Y,-Ball.Size.Y/2,math.huge),vel.Z)
end
if vel.Magnitude <= 0.00022 then
vel = Vector3.zero
end
velWithoutY = Vector3.new(vel.X,0,vel.Z)
Ball.Position += vel;
Ball:SetAttribute("Velocity",velWithoutY:Lerp(Vector3.new(0,0,0),.05)+Vector3.new(0,vel.Y,0))
end
end)