Need Help with Ray Beam Look Vector

I would like to have a beam go in the lookvector of the part and stop exactly when the ray hits something.

However this seems to happen. It’s close but unfortunately it seems it will offset depending on the rotation. It will change the amount of offset depending on the rotation, however whats strange is that my raycast works great, however the beam thats meant to replicate the raycast is offset. So all it is is a visual bug, however im not very sure why.

I have tried to use a few different ways of calculating it however it doesnt seem to work anymore.

Heres the part of code I think is wrong with also the raycasting

			local ray = Ray.new(caster.Position, caster.CFrame.LookVector * 2000)
		
			local hitPart, hitPosition = workspace:FindPartOnRay(ray)
				
			local Distance  = (caster.Position - hitPart.Position).Magnitude 
			
			caster.BeamEndAttachment.Position = (caster.CFrame.lookVector)*Distance

would be great if i could find a solution, as I really enjoy working with the Beam particle, and i personally think its more efficient than a block.

1 Like

Don’t change the BeamEndAttachment’s position; keep it the same as it was in studio. An Attachment’s CFrame is relative to its parent’s CFrame relative to the world, so the Attachment’s World Position will always be: ParentCFrame * offset. If your offset was, let’s say, 5 studs in the -z direction, the attachment will always be 5 studs in front of the part, or 5 studs in the direction of the front surface

1 Like

Just change it to:

BeamEndAttachment.Position = Vector3.new(0, 0, -distance)
1 Like