Rotate a character such that the tool faces a specific point

My task here is to get the linked sword to be facing the green dot, and not the body itself. In other words, I want the sword to get as close as possible to the player.

I’ve tried rotating the sword itself, expecting that the character would go along with it (to no avail, most likely because of negative IQ).

Anyway, I think the resolution would be to calculate some magic number that serves as a CFrame for the HumanoidRootPart, which accounts for the sword’s Position / Rotation.

The code I’m using in the picture above is basically:

local lookAt = CFrame.lookAt(
    humanoidRootPart.Position, 
    Vector3.new( -- This extra code is so that the character doesn't lean into green dot. I simply want it to face the point.
        greenDot.Position.X, 
        humanoidRootPart.Position.Y, 
        greenDot.Position.Z
    )
)

humanoidRootPart.CFrame = lookAt;

So, uhh… Any big brains out there (explain to me like I’m 5 years old)?

Trigonometry should work if you can find the lengths l1 and l2 you can exactly calculate the angle of rotation then add it onto the look at CFrame. Or you can estimate it I would say it’s around 20 degrees.

humanoidRootPart.CFrame = lookAt*CFrame.Angles(0,math.rad(20),0);

You’re right, an estimate did work for this use case. But, for future reference, how would I go about discovering L₁ and L₂? (in case something comes up and I need extra precision)

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