Hello scripters, I am trying to ray cast a laser to follow a player but just behind so then they can actually run away, how do I do this so it is always behind them no matter what?
You would have to edit the distance variable to be accurate to the new distance, but yes multiply it with what you have
I don’t currently see why it would fling and I hope it doesn’t but you’d have to fill me in on what happens
local function castRay(rTarget)
--print("Target in castRay is set to"..rTarget)
local laser_Thickness = .5
local rayOriginPart = Eye
local rayTargetPart = rTarget
local origin = rayOriginPart.CFrame.Position
local rayTarget = rayTargetPart.HumanoidRootPart.CFrame.Position
local direction = (rayTarget - origin)
local results = workspace:Raycast(origin, direction, RayCastParameters)
if not results then
results = {Position = rayTarget}
end
local distance = (results.Position - origin).Magnitude
LaserPart.Size = Vector3.new(laser_Thickness,laser_Thickness,distance)
LaserPart.CFrame = CFrame.new(origin, rayTarget - rTarget.Humanoid.MoveDirection) * CFrame.new(0,0, -distance / 2)
--game.ReplicatedStorage.EyeEvent:FireAllClients(origin, rayTarget, distance, LaserPart)
end
local target
EyeEventRemote.OnClientEvent:Connect(function(Target)
target = Target
RunService.RenderStepped:Connect(function()
castRay(target)
end)
end)
Blacklisting the laser might solve your problem, I think its hitting the laser part and using that distance as the new distance
Once it gets yeeted out of the way it can cast all the way to the character unblocked, which would explain the “alternating” behavior
Why not put a wait(1) in the script before firing the laser. If you want don’t want the laser to jump every second you may be able to Lerp the laser to the next point.
If the player moves it’ll pick up their Position, wait, then lerp to that Position. If the player moves it’ll never catch them. You may need to adjust the wait(1) higher or lower to adjust how close the laser gets though.
They want the laser to track and follow the player if they are walking, but if the player stops then it catches up and kills them.
My suggestion was to try to make it lag behind their Position with the wait(x), so if they stop the Position of the laser would update and move to their stopped Position.