CFrame.LookAt() doesn't position correctly

Im trying to fire a Raycast out of an Attachment which works fine, then i position my attachment (which also works fine) and a Part (LaserPoint) works too, if i use ONLY the Position

local StartPosition = StartAttachment.WorldPosition
local Direction = StartAttachment.WorldCFrame.LookVector * 10000
			
local Raycast = workspace:Raycast(StartPosition, Direction, RaycastParameter)
if Raycast then
	EndAttachment.WorldPosition = Raycast.Position
	LaserPoint.CFrame = CFrame.lookAt(Raycast.Position, Raycast.Position + -Raycast.Normal) -- The Problem
end

I want the Part to face the Normal of the Raycast’s Instance tho. In my other script which creates bulletholes this works completely fine, which makes me wonder why this doesnt work.

NewBulletHole.CFrame = CFrame.lookAt(Raycast.Position, Raycast.Position + Raycast.Normal)

The Part is completly fine since when i change the just position it works fine but doesnt face the normal of the Instance.

Thanking in advance! :grinning:

1 Like

What exactly do you mean by it doesn’t position correctly? I tried your code in a new place and I can’t appear to replicate the issue. It may be caused by something else in the code.

The positioning is correct, the rotation isnt. CFrame.LookAt() should do it for me which works in other scripts but here it just doesnt seem to work at all. The Part should face the same direction of the parts normal (which is just for 6 sides so even with mesh parts it will look bad)

Excuse me for my bad wording, but i cant seem to explain it otherwise. And yes, i have already looked that other scripts may interfere.

Does the current script do anything to the orientation of LaserPoint? It could be that the front face of the part is incorrect, so it appears to be facing the wrong way when you use CFrame.lookAt()

Currently im just facing the part to the players camera, since lookAt() doesnt work. And the part is facing the correct direction. To note, when i playtested i searched it up in workspace and saw noticed that the part is unanchored when i do it and falls trough the map with no collision aswell, eventho both of them are turned on.

Small adjustment:

local StartPosition = StartAttachment.WorldPosition
local Direction = StartAttachment.WorldCFrame.LookVector * 10000

local Raycast = workspace:Raycast(StartPosition, Direction, RaycastParameter)
if Raycast then
	EndAttachment.WorldPosition = Raycast.Position
	LaserPoint.CFrame = CFrame.lookAt(Raycast.Position, Raycast.Position + Raycast.Normal)
end

If it’s not working as expected, it could be due to the orientation of the part itself or how it’s modeled. You might want to check the part’s original orientation or manually adjust…

LaserPoint.CFrame = CFrame.lookAt(Raycast.Position, Raycast.Position + Raycast.Normal) * CFrame.Angles(math.rad(90), 0, 0)

If this isn’t working … I’d check the the part’s orientation in Blender. Might also be able to fix a problem with this using the Studio’s MODEL / Align Tool…
This would be assuming the part’s original orientation is off a bit.

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