local function applySmoothForce(hit, direction, magnitude, duration)
local force = Instance.new("BodyVelocity")
force.MaxForce = Vector3.new(4e+006,4e+003,4e+006)
force.P = 4 -- lower P value
force.Velocity = direction.Unit * magnitude
force.Parent = hit
local S = Instance.new("BodyAngularVelocity")
S.AngularVelocity = Vector3.new(0, -1, 0)
S.MaxTorque = Vector3.new(0, math.huge, 0)
S.Parent = hit
game.Debris:AddItem(S, duration)
-- gradually decrease force over time
local dt = 0.1 -- decrement time interval
while duration > 0 do
force.Velocity = force.Velocity - direction.Unit * (magnitude * dt / duration)
wait(dt)
duration = duration - dt
end
-- remove the force
force:Destroy()
end
-- example usage:
local direction = plr.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector
applySmoothForce(hit, direction, 50, 0.3)