Offsetting a cframe to go just behind a player depending on look vector?

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?

What I currently have:

https://gyazo.com/f2324faca45701e2637f514c761683ed

The current way I calculate where to go:

	LaserPart.CFrame = CFrame.new(origin, rayTarget) * CFrame.new(0,0, -distance / 2)

What I want (The red line is what I have, the black is a demonstration of what I want):

fdasgqsjg

If they stand still do you want them to get hit or do you want it to still fire behind them?

I want them to be hit, so basically I want to give them a chance to run but if still they get hit+

I would probably do something like

CFrame.new(origin, target - humanoid.MoveDirection) ...

Multiply that by what I have? That would fling it really far would it not?

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

With just multiplying it I get this as a result,

https://gyazo.com/268b1160d68f1c443de1d39bf15c4c45

That seems strange, what is your code?
Is it along the lines of this?

	LaserPart.CFrame = CFrame.new(origin, rayTarget - humanoid.MoveDirection) * CFrame.new(0,0, -distance / 2)

Perhaps I wasn’t as specific as I should be and that’s what caused the problem

Awesome, now any ideas on how to fix this flickering?

https://gyazo.com/be389088b26460f7d698b27576ea3493

Code:

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)

Where is it going when its flickering? For example is it going to (0,100000000,0), to another target, under the map, etc?

As you can see, it is changing even if I am standing still, it shouldn’t be switching target so isn’t that I don’t think.

https://gyazo.com/0db1427b782a4fcb71cc36ff7c93099e

Are you blacklisting the laser part?

Nope!

local RayCastParameters = RaycastParams.new()
RayCastParameters.FilterDescendantsInstances = game.Workspace.HappyHome.Home.EyeOfSauron.Eye.Parent:GetChildren()
RayCastParameters.FilterType = Enum.RaycastFilterType.Blacklist

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.

Now it doesn’t show so blacklisting I don’t think will work

Pretty sure it’s not just firing lasers. It’s a laser that tracks the human which renders the wait(1) solution useless.

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.