Hi there! I’m trying to make a laser turret (pending texture) that chases players with a laser. The focusing on players and chasing them part is done, but I’m attempting to use raycasting to position a beam attachment which stands as the end of the laser and the position of a laserdamage particle, although the raycasting I’m attempting to use is going horribly wrong.
The raycast method I have concocted so far is as follows:
local rayOrigin = script.Parent.LaserPos.Position
local rayDirection = script.Parent.LaserPos.Orientation
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent.LaserPos.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if (raycastResult == nil) then
print("nil")
end
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.Transparency == 0 then
workspace.t.CFrame = CFrame.new(raycastResult.Position)
end
end
I made it using this guide.
The raycast intersection position point is t
which is selected using the move tool to make its position more obvious.
The issues are that the position the raycast is giving as an intersection is under the baseplate and in the wrong place, the raycast doesn’t detect half the circumference around it (which is when the console prints nil
), instead of the raycast position moving around with the player, instead it moves in an exponential accelerating line, and when the raycast is left for a while (it repeats every few milliseconds), it slowly descends which you can see at the start of the video.
I assume this is something to do with the direction that I’ve set the raycast to look, but I don’t know what else to set it to. Any help would be greatly appreciated!