Making Laser position correctly outside of part

I am creating a gun-like thing and I’m trying to get this laser beam to be positioned correctly. I have it rotating correctly, but it’s position is slightly off and I’m sure my math is just way off but I’m confused.

It works when my mouse is directly ahead of me and I have no difference in height, but when I aim down or up at all, it totally messes up.

My code:

	local startPos = PointStart.Position
	
	local lookFromPosition = startPos + (PointStart.CFrame.LookVector)
	newBeam.CFrame = CFrame.lookAt(lookFromPosition, mousePos)

What is happening (The position offset is inconsistent):

What I am trying to make it like:

2 Likes

I found the issue:

local LaserCFrame = CFrame.new(startPos, GoalPosition)
newBeam.CFrame = LaserCFrame + (LaserCFrame.LookVector * newBeam.Size.Z / 2)

this fixes it.
CFrame.new could be changed to CFrame.lookAt() as well.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.