I am trying to make a projectile that ricochets but havent been able to do it.
Events.DoMove.OnServerEvent:Connect(function(plr, ...)
local args = {...}
local InputInfo = args[2]
local MoveName = args[1]
local Character = plr.Character or plr.CharacterAdded:Wait()
if MoveName == "Ball Throw" then
local Ball = Objects.SteelBall:Clone()
Ball.Parent = workspace
Ball:PivotTo(Character.HumanoidRootPart.CFrame)
local stepDistance = 10
local LV = CFrame.lookAt(Character.HumanoidRootPart.Position, InputInfo["MouseCFrame"].Position).LookVector
local BallVelocity = Instance.new("BodyVelocity")
BallVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BallVelocity.Velocity = LV * stepDistance
BallVelocity.Parent = Ball
local something
local RParams = RaycastParams.new()
RParams.FilterType = Enum.RaycastFilterType.Exclude
RParams.FilterDescendantsInstances = {Ball,Character}
local start = os.clock()
local Connection
Connection = RunService.Heartbeat:Connect(function()
local result = workspace:Raycast(Ball.Position,LV * 5,RParams)
if result then
local norm = result.Normal
local reflect = BallVelocity.Velocity - (2 * BallVelocity.Velocity:Dot(norm) * norm)
BallVelocity.Velocity = reflect
something = stepDistance - (result.Position - Ball.Position).Magnitude
return
end
if os.clock() - start >= 2.5 then
Ball:Destroy()
Connection:Disconnect()
end
end)
end
end)
Here is my current script.
https://streamable.com/6d4jwj
Heres whats going on