I am trying to make a ricocheting bullet and at first, it appeared to be working, but after some testing, I found some strange inconsistencies why is this happening? (Video and code below) Its4Realzies's Place Number_ 37 - Roblox Studio 2021-05-27 17-37-37
--Creates bullet
local bullet = Instance.new('Part')
bullet.Name = 'Bullet'
bullet.CanCollide = false
bullet.Color = sP.Color
bullet.Material = 'Neon'
bullet.Shape = 'Ball'
bullet.Size = Vector3.new(bulletsize, bulletsize, bulletsize)
bullet.CFrame = sP.CFrame
--Creates bodyVelocity
local bodyVelocity = Instance.new('BodyVelocity', bullet)
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Velocity = bullet.CFrame.lookVector * sP.Speed.Value
bullet.Parent = sP
game.Debris:AddItem(bullet, sP.BulletDeletionDelay.Value)
bullet.Touched:Connect(function(part)
if part.CanCollide and part ~= sP and part.Parent ~= sP then
local h = part.Parent:FindFirstChild'Humanoid'
if h and part:IsDescendantOf(plrCharacter) then
bullet:Destroy()
game.ReplicatedStorage.DamageEvent:FireServer(sP.Damage.Value)
else
local startCFrame = bullet.CFrame
local normal = startCFrame.lookVector
local position = startCFrame.p
local ray = Ray.new(position, normal * 500)
local hit, position, surfaceNormal = game.Workspace:FindPartOnRay(ray) --Cast ray
if (hit) then
--Get the reflected normal
local reflectedNormal = (normal - (2 * normal:Dot(surfaceNormal) * surfaceNormal))
--Set new normal
normal = reflectedNormal
end
bullet.BodyVelocity.Velocity = normal * sP.Speed.Value
end
end
end)