Hello, I want to make a bullet bounce from a part. It kind of works, but 1 major problem: The bullet’s speed suddenly becomes really fast and starts to ignore parts it touches. Can anyone help me?
Here’s my code:
local function OnRayHit(origin, direction, hitPart, hitPoint, normal, material, segmentVelocity, cosmeticBulletObject, hitData)
-- This function will be connected to the Caster's "RayHit" event.
local ShowEffects = ScreenCullingEnabled and (ScreenCulling(hitPoint, ScreenCullingRadius) and (hitPoint - Workspace.CurrentCamera.CFrame.p).Magnitude <= RenderDistance) or (hitPoint - Workspace.CurrentCamera.CFrame.p).Magnitude <= RenderDistance
local x = math.random(0,100)
if x <= 100 and not cosmeticBulletObject:FindFirstChild("Bounced") then
--local CurrentDirection = segmentVelocity.Unit
local CurrentDirection = segmentVelocity.Unit
local NewDirection = CurrentDirection - (2 * CurrentDirection:Dot(normal) * normal)
local n= NewDirection * segmentVelocity.Magnitude
local bv = Instance.new("BoolValue")
bv.Name = "Bounced"
bv.Parent = cosmeticBulletObject
cosmeticBulletObject.CFrame = cosmeticBulletObject.CFrame + n
return
end
I will only provide 1 part of the function.
Any help is appreciated. (Moving the code into another function, etc.)