Camera look in the direction of X axis of attachment

I want to make camera look in the direction of X axis of attachment.

image

I Used worldCFrame, toWorldSpace, etc. but didnt work. When using worldCFrame camera goes to position of attachment but orientation doesnt seem correct if we assume the face of attachment is that yellow vector. It can be solved by LookAt but thats not right way to solve.

The direction of the primary (yellow) axis of an attachment is Attachment.WorldAxis I am pretty sure.

And if you want the secondary axis of the attachment to be the UpVector, you can use Attachment.WorldSecondaryAxis.

With these 2 properties, you can create the matrix you need for CFrame.fromMatrix().

local LookVector = -Attachment.WorldAxis -- For some reason Roblox needs a negative LookVector
local UpVector = Attachment.WorldSecondaryAxis 
local RightVector = LookVector:Cross(UpVector) --> (Correct me if I am wrong here)
local Position = ...

local CFrame = CFrame.fromMatrix(Position, RightVector, UpVector, LookVector)

Tell me if I said something wrong.

2 Likes

Yeah, thanks man it worked, But another problem raised.
image
image
i dont know why but it shows inside of the models or smt after changing cframe

Might be because one of the vectors of the matrix is inversed. Try multiplying the LookVector with -1.

Yeah it happened after putting negative to wordAxis, lemme try.
Yeah worked after putting negative to Right Vector, thanks.

1 Like

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