Hello! I am wondering how to make a curved trajectory for a ball while using custom physics because when I try to it does an upside-down V shape instead. I am trying to avoid bezier curves because they will make it difficult to account for gravity. This is what my code looks like right now:
function module.Stepped(ball)
local prevpos
local stepped
local bouncing = false
local canbounce = true
local bouncefactor = 0.5
local i = 0
local justbounced = false
local hitpeak = false
local peak = 20
local maxbounce = 3
local bounces = 0
stepped = run.RenderStepped:Connect(function(dt)
if not bouncing then
i +=dt
elseif bouncing then
i-= dt
end
if ball.Parent.Parent == nil then stepped:Disconnect() end
if prevpos and ball:GetAttribute("LerpID") == nil and not bouncing then -- checks if the ball hasn't been hit yet
ball:SetAttribute("Velocity", Vector3.new(0, -workspace.Gravity/500 ,0) )
ball.Position += ball:GetAttribute("Velocity") * i
elseif not prevpos then
ball:SetAttribute("Velocity", Vector3.new(0, -workspace.Gravity/500 ,0) )
ball.Position += ball:GetAttribute("Velocity") * i
end
local rayparams = RaycastParams.new()
rayparams.CollisionGroup = "ServerBall"
rayparams.IgnoreWater = true
local groundray = workspace:Raycast(ball.Position, Vector3.yAxis * -1, rayparams)
if groundray then
if groundray.Instance and (groundray.Instance.Name == "Court" or groundray.Instance.Name == "Baseplate") and justbounced == false and canbounce == true and bounces < maxbounce then
canbounce = false
bouncing = true
justbounced = true
bounces += 1
ball.Anchored = true
print("bounce")
ball:SetAttribute("Velocity", ball:GetAttribute("Velocity") * Vector3.new(1,-1,1) * bouncefactor)
justbounced = false
task.spawn(function()
task.wait(0.3)
canbounce = true
end)
elseif bounces >= maxbounce then
bouncing = false
end
end
if bouncing == true and justbounced == false then
if math.abs(ball.Position.Y - peak) < 2 and ball:GetAttribute("Velocity").Y > 0 then
hitpeak = true
ball:SetAttribute("Velocity", Vector3.new(0, -workspace.Gravity/500,0))
bouncing = false
peak = peak/1.7
i=0
task.wait(0.2)
hitpeak = false
else
local gravity = Vector3.new(0, workspace.Gravity, 0)
print(ball:GetAttribute("Velocity"))
ball.Position += (ball:GetAttribute("Velocity") ) * i
end
end
prevpos = ball.Position
end)
end
There is no x and z axis implementation yet. Help is appreciated; thank you!