so ive been using kinematic formula for simulating my ball movment but for some reason when its done my ball has no physics to it and i just need help with it thx in advance
(https://gyazo.com/e0af3cb33647f07a401cef205c5c9917)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local clientEffects = ReplicatedStorage.Remotes
local Shoot = {}
function Shoot.new(Gravity, WhiteList, Wind, Despawntime, MaxBounces, Decay, Threshold, Visulize)
local newKick = {}
newKick.Gravity = Gravity or 9.8
newKick.Wind = Wind or Vector3.new(0,0,0)
newKick.Threshold = Threshold or 0.1
newKick.MaxBounces = MaxBounces or 3
newKick.Decay = Decay or 0.8
newKick.Despawntime = Despawntime or 3
newKick.Visulize = Visulize or false
newKick.Params = RaycastParams.new()
newKick.Params.FilterType = Enum.RaycastFilterType.Include
newKick.Params.FilterDescendantsInstances = WhiteList
function newKick:Cast(Start, dest, vel)
local conversion = 192.2 / 9.8
local velocity = (dest - Start).Unit * vel * conversion
local a = Vector3.new(newKick.Wind.X, newKick.Wind.Y - newKick.Gravity * 9.8, newKick.Wind.Z) * conversion
local t = 0
local totalTime = 0
local bounces = 0
local currentVelocity = velocity
local currentPos = Start
local rayResult = nil
local found = false
local index = tick()
clientEffects.BallShoot:FireAllClients(index)
local Connection
Connection = RunService.Heartbeat:Connect(function(dt)
if found then
Connection:Disconnect()
return
end
t += dt
totalTime += dt
currentVelocity = velocity + a * t
local projPos = Start + velocity * t + 0.5 * a * t * t
rayResult = workspace:Raycast(currentPos, projPos - currentPos, newKick.Params)
clientEffects.BallUpdate:FireAllClients(index, currentPos, projPos)
currentPos = projPos
if self.Visulize then
local part = Instance.new("Part")
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Position = projPos
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Neon
part.Color = Color3.fromRGB(255, 0, 4)
part.Shape = Enum.PartType.Ball
part.Parent = workspace
Debris:AddItem(part, 0.5)
end
if rayResult then
bounces += 1
t = 0
if bounces < newKick.MaxBounces then
velocity = 0.9 * (currentVelocity - 2*currentVelocity:Dot(rayResult.Normal) * rayResult.Normal)
if velocity.Magnitude < self.Threshold then
velocity = velocity * 0.8 -- Reduce speed gradually instead of stopping
if velocity.Magnitude < 0.5 then -- If it's too slow, THEN stop it
found = true
end
end
Start = rayResult.Position
currentPos = rayResult.Position
else
print("Current Velocity:", velocity.Magnitude)
found = true
end
end
if totalTime > self.Despawntime then
found = true
end
if found then
local currentBall = workspace:FindFirstChild("Ball")
print(workspace.Ball.Anchored) -- Should print false
local weld = currentBall:FindFirstChildOfClass("WeldConstraint")
if weld then
weld.Enabled = false -- Disable it for movement
end
if currentBall then
print("Ball handing control to physics")
currentBall.AssemblyLinearVelocity = velocity -- Keeps rolling
currentBall.AssemblyAngularVelocity = Vector3.new(0, 3, 0) -- Adds spin
end
end
end)
end
return newKick
end
return Shoot```