You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want my raycast to bounce off walls ,floors and ceilings by the number of charges you did
- What is the issue? Include screenshots / videos if possible!
(It went through the wall)
Behavior
(The blue line)
Expected behavior
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to change the distance and timegaps to be as little as possible but it didn’t work
local numbounce =0
local partNBeams = {}
local function Shoot()
local maxDistance = 200
local curDistance = 0
local stepDistance = 0.01
local stepWait = 0
local currentPos = shoot_part.Position
local currentNormal = (position - currentPos).Unit*300
local function Step(overrideDistance)
-- Cast ray:
local params = RaycastParams.new()
local direction = currentNormal * (overrideDistance or stepDistance)
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {script.Parent.Body,player.Character}
local result = workspace:Raycast(currentPos, direction)
local pos
if result then
pos = result.Position
else
pos = currentPos + direction
end
VFXR:FireAllClients(currentPos,pos)
local oldPos = currentPos
currentPos = pos
if result then
numbounce +=1
print(timechargd,numbounce)
if numbounce >= timechargd then
print("More")
return
end
-- r = d - 2(d DOT n)n
-- Reflect:
if result.Instance:FindFirstAncestorOfClass("Model") then
if result.Instance:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid") then
if result.Instance:FindFirstAncestorOfClass("Model"):HasTag("Enemy") then
result.Instance:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid").Health -= tool:GetAttribute("Damage")
end
end
end
local norm = result.Normal
local reflect = (currentNormal - (2 * currentNormal:Dot(norm) * norm))
currentNormal = reflect
Step(stepDistance - (pos - oldPos).Magnitude)
return
end
curDistance = (curDistance + (pos - oldPos).Magnitude)
-- Recurse if max distance not reached:
if curDistance < maxDistance then
task.wait(stepWait)
Step()
end
end
Step()
print("Goodbye")
-- Done! Destroy laser:
end
Shoot() -- Fire shot!
Here’s the code
(OG code)
Hopefully i didn’t phase it wrong. Never did a scripting support post before lol
Thanks for helping!