So, I am trying to create an attack where a user lauches a projectile forward, and the projectile should stop/break whenever it comes in contact with anther brick. For this, I have been utilizing raycasting (as the projectile "moves" via changing its CFrame).
For whatever reason, the part of my code that detects obstacles only seems to work well with small obstacles (like short, thin walls) rather than what most of my game is built with (larger, thicker blocks of earth). Is there a reason for this? It seems like a runtime error more than a logic error, but I'm open to suggestions (as I'm fairly new to this).
Here is the part of my code that detects obstacles. You can ignore most of the lines that don't pertain to actual raycasting.
for i = 0, 75, 1 do -- Moves the projectile forward.
wait()
if sensor.Name ~= 'DeadTornadoToss_' .. player.Name then
tornado:SetPrimaryPartCFrame(tornado:GetPrimaryPartCFrame() - tornado:GetPrimaryPartCFrame().LookVector * 1.5)
ray = Ray.new(sensor.CFrame.p - sensor.CFrame.LookVector * 5, sensor.CFrame.LookVector) -- origin, direction
ray2 = Ray.new(sensor.CFrame.p - sensor.CFrame.LookVector * 5 + sensor.CFrame.RightVector * 3, sensor.CFrame.LookVector) -- origin, direction
ray3 = Ray.new(sensor.CFrame.p - sensor.CFrame.LookVector * 5 - sensor.CFrame.RightVector * 3, sensor.CFrame.LookVector) -- origin, direction
end
local part, hitPosition = workspace:FindPartOnRay(ray)
local part2, hitPosition2 = workspace:FindPartOnRay(ray2)
local part3, hitPosition3 = workspace:FindPartOnRay(ray3)
if part or part2 or part3 then
if part then
obstacle = part:FindFirstAncestorOfClass("Model")
else if part2 then
obstacle = part2:FindFirstAncestorOfClass("Model")
else if part3 then
obstacle = part3:FindFirstAncestorOfClass("Model")
end
end
end
if obstacle ~= nil then
if obstacle:FindFirstChild("Humanoid") == nil then
print("Hit part")
sensor.Name = 'DeadTornadoToss_' .. player.Name
tornado.SmallTornado.Transparency = 1
break
end
else
print("Hit part")
sensor.Name = 'DeadTornadoToss_' .. player.Name
tornado.SmallTornado.Transparency = 1
break
end
end
end

1 comment
bump. Please help.