CFrame Look At while maintaining same angle help

I’m just messing around using two attachments with a first-person ViewModel to position each arm using CFrame(Pos1,Pos2) when I ran into this problem. I want the arms to be angled towards the end position while maintaining the same upvector and the rest of the rig.

As seen in this gif it’s always pointed upwards.
https://gyazo.com/8f1ea6937c4a479d3b2bf5a87ae37849

LeftArm.CFrame = CFrame.new(LeftStart.WorldPosition,LeftEnd.WorldPosition)
RightArm.CFrame = CFrame.new(RightStart.WorldPosition,RightEnd.WorldPosition)

2 Likes

Seems like a problem with CFrame.new() at high pitch angles from:

At high pitch angles (around 82 degrees), you may experience numerical instability. If this is an issue, or if you require a different up vector, it’s recommended you use CFrame.fromMatrix instead to more accurately construct the CFrame. Additionally, if lookAt is directly above pos (pitch angle of 90 degrees) the up vector switches to the X-axis.

Like it says try using CFrame.fromMatrix instead by using the attachments rightvector

1 Like

How would I convert it to CFrame.fromMatrix(), I’m confused by the whole concept.

1 Like

Well, the position vector is the same in your case it would be:

LeftArm.CFrame = CFrame.fromMatrix(LeftStart.WorldPosition, .....)

Then you would need to follow the example from the API-Reference:

function lookAt(target, eye)
    local forwardVector = (target - eye).Unit
    local upVector = Vector3.new(0, 1, 0)
    -- Remember the right-hand rule
    local rightVector = forwardVector:Cross(upVector)
    local upVector2 = rightVector:Cross(forwardVector)
 
    return CFrame.fromMatrix(eye, rightVector, upVector2)
end

where the Forward vector is the vector from the LefStart to the LeftEnd world position.

1 Like