I am making special abilities that damage parts. What I mean is imagine I have a lightning strike that I can use to hit the ground; when the lightning touches the ground, an event would happen. The problem is, since the bomb is anchored, Part.Touched will not work in this scenario. What can I use instead?
You could use Raycasting. Just fire rays towards the ground to detect if they’re touching, but I’m not sure why .Touched wouldn’t work if the object is anchored, .Touched works either way
How would I do that? (Not familiar with raycasting;)
BasePart.Touched documentation:
This event only fires as a result of physical movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be Anchored at the time of the collision.
For example, when you finish your animation, fire a ray towards the ground and detect if it collided with something.
local rayOrigin = Vector3.new(0, 0, 0) -- What position you want to shoot the ray from.
local rayDirection = Vector3.new(0, -50, 0) -- How far you want to raycast (X, Y, Z)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if raycastResult then
print("Hit: " .. raycastResult.Instance)
end
The part touches the ground, however, nothing is being printed in the output.
(pos is the position of the players mouse)
local rayOrigin = Vector3.new(spiritbomb.Position)
local rayDirection = Vector3.new(pos)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
for i = 1, 250, 1 do
spiritbomb.CFrame *= CFrame.new(0, 0, -1.5)
if raycastResult then
print("Hit: " .. raycastResult.Instance)
end
task.wait(0.01)
end