so i recreated the last prism from terraria, but the projectile it makes kind of sucks.
first off, it does the normal raycast hitbox. i TRIED to use shapecasts but it just turned the cube beams to cylinders and they weren’t alligned correctly. i wish i recorded it
second off, the raycast constantly detects where the mouse or part is, so the beams stack on eachother before resetting
flashing lights warning bad raycast
bad hitbox
here’s the snippets of code where the bugs happen, the part instance (lasers) is meant to be damaging, not the raycast. how do i convert it to a shapecast, and preferably with cylinders?
local script
local folder = game.Workspace.Ignored
-
mouse.TargetFilter = folder
tool.Activated:Connect(function()
if dbtool == true then
return end
dbtool = true
dbtrigger = true
while dbtrigger == true do
--print(tool:GetChildren())
local begin = tool.Start.Position
local finish = mouse.Hit.Position
remote:FireServer(tool, begin, finish)
task.wait(cooldown)
end
dbtool = false
end)
server script
local direction = (finish - begin).Unit * range
local detect = game.Workspace:Raycast(begin, direction)
if detect and not prismFunction(begin, direction) then
print(detect.Instance.Name)
local mark = detect.Instance.Parent
local core = mark:FindFirstChild("Humanoid")
if core then
if mark.Name ~= player.Character.Name then
if detect.Instance.Name == "Head" then
core.Health -= critical
else
core.Health -= damage
end
end
end
end
prismFunction(begin, direction)
end)
you should use raycast params which can make your raycast ignore certain instances
here’s the docs for it
you can use this in ur case like so:
local direction = (finish - begin).Unit * range
local folder = ... -- make this a folder where u place all the parts u want to ignore here
local params = RaycastParams.new()
params.FilterDescendantsInstances = folder:GetChildren()
params.FilterType = Enum.RaycastFilterType.Exclude -- this means to ignore all objects inside the folder
local detect = game.Workspace:Raycast(begin, direction, params) -- we add params to the raycast args
if detect and not prismFunction(begin, direction) then
print(detect.Instance.Name)
local mark = detect.Instance.Parent
local core = mark:FindFirstChild("Humanoid")
if core then
if mark.Name ~= player.Character.Name then
if detect.Instance.Name == "Head" then
core.Health -= critical
else
core.Health -= damage
end
end
end
end
prismFunction(begin, direction)
end)
in order to add the laser beams ur making inside the folder you just parent them to the folder when u create them like so:
local laser = ....:Clone() -- or watever the way ur making it
laser.Parent = folder -- make sure its the same folder used in the raycast params
yeah its not that hard,
shapecasting is basically raycasting but its more custumizable
you can cast rays in different shapes, sizes.
there’s currently 2 types os shapecasting:
Blockcast, Spherecast
local tool = game.StarterPack.Apotheosis
local laser = replicate.prismRemote.Laser_PrismRemote
local function prismFunction(begin, direction)
local center = begin + direction / 2
local distance = direction.Magnitude
local random = Random.new()
local folder = game.Workspace.Ignored
local projectile = Instance.new("Part")
projectile.Parent = folder
projectile.Anchored = true
projectile.CanCollide = false
projectile.Material = Enum.Material.Neon
projectile.Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
projectile.CFrame = CFrame.new(center, begin)
projectile.Size = Vector3.new(3, 3, distance)
local fade = tweens:Create(projectile, TweenInfo.new(time), {Transparency = 1}):Play()
debris:AddItem(projectile, .1)
end
laser.OnServerEvent:Connect(function(player, tool, begin, finish)
local damage = tool:GetAttribute("Damage")
local critical = tool:GetAttribute("Critical")
local range = tool:GetAttribute("Range")
tool.shot:Play()
local direction = (finish - begin).Unit * range
local folder = game.Workspace.Ignored
local params = RaycastParams.new()
params.FilterDescendantsInstances = folder:GetChildren()
params.FilterType = Enum.RaycastFilterType.Exclude
local detect = game.Workspace:Raycast(begin, direction, params)
if detect and not prismFunction(begin, direction, params) then
print(detect.Instance.Name)
local mark = detect.Instance.Parent
local core = mark:FindFirstChild("Humanoid")
if core then
if mark.Name ~= player.Character.Name then
if detect.Instance.Name == "Head" then
core.Health -= critical
else
core.Health -= damage
end
end
end
end
prismFunction(begin, direction)
end)