How to reflect rays on hit

Firstly I think it is a bad idea impulsing the character every step you should probably just impulse once but that is might not be causing the problem. You should have the step distance be the equal amount of how much you are apply the impulse (knockback/2)/400 -- needs to also be the step distance which is probably why it is reflecting immediately before finishing it.

This is a great demonstration of the application of this formula, but was made so long ago with the deprecated RayCasting functions. I took 5 minutes to revise it and made it into an up-to-date version. Laser Reflection - Roblox

1 Like

Sorry for bumping but I’ve encountered an issue. I’ve searched FAR and I mean hours of searching to find the fix for this and I haven’t. If I fire the raycast on one side, the raycast works but if I fire it on other sides the raycast deflection goes the same way as the normal side. I would highly appreciate help.

info[3][3] = result normal

Server:

						plr.leaderstats.Kills.Value += 1
									t.gun:FireClient(plr, hum.Parent.Name, (workspace[plr.Name].PrimaryPart.Position-hum.Parent.PrimaryPart.Position).magnitude)

								end)
								wait(.001)
								died:Disconnect()
								
						end
						elseif Part.Name == 'shield' then
							local lv = t.Handle.CFrame.LookVector 
							wait(.1)	
							
							t.gun:FireClient(plr, 
								info[3][2], 
								lv-((2*lv:Dot(info[3][3])) * info[3][3] ))
				end
					end

Client:

local Raycast = workspace:Raycast(
	origin, 
	((direction - origin).Unit) * maxdist, 
	params)		
local Position
local Part
local Distance
local Normal

if not Raycast then		
	Distance = maxdist	
	Position = origin + (((origin - origin).Unit) * maxdist)
else
	Position = Raycast.Position
	Part = Raycast.Instance
	Distance = (origin - Position).magnitude	
	Normal = Raycast.Normal
end

local inner = Instance.new('Part', workspace:WaitForChild('bullets'..plr.Name, 5))
inner.Size = Vector3.new(0.1, 0.1, Distance)
inner.Color = Color3.fromRGB(255, 255, 255)
inner.Anchored = true
inner.CanCollide = false
inner.Material = Enum.Material.Neon
inner.CFrame = CFrame.new(origin, Position) * CFrame.new(0, 0, -inner.Size.Z / 2) 

local outer = Instance.new('Part', workspace:WaitForChild('bullets'..plr.Name, 5))
outer.Size = Vector3.new(0.2, 0.2, Distance)
outer.Color = Color3.fromRGB(0, 150, 255)
outer.Transparency = 0.5
outer.Anchored = true
outer.CanCollide = false
outer.Material = inner.Material
outer.CFrame = inner.CFrame

local values = {['outer'] = outer, ['Part'] = Part, ['Position'] = Position, ['inner'] = inner, ['Normal'] = Normal}	

game.Debris:AddItem(inner, 0.075)
game.Debris:AddItem(outer, 0.075)
return values

end

Change the deprecated Enum.Raycast thing to Exclude

1 Like