im trying to fix my ricochet code to not make the bullet go through the wall after bouncing off using the ray pierced event from fastcast
video:
code:
local function Reflect(surfaceNormal, bulletNormal)
return bulletNormal - (2 * bulletNormal:Dot(surfaceNormal) * surfaceNormal)
end
function RayPierced(cast, result, velocity, bullet)
local position = result.Position
local normal = result.Normal
local newNormal = Reflect(normal, velocity.Unit)
cast:SetVelocity(newNormal * velocity.Magnitude)
cast:SetPosition(position)
end
is there anyway to make it no go through the wall?