Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make sense of CFrame methods?

My reason for asking, is that I'm experimenting taking a vector3 (in my case, mouse.Hit.p), and turning it into a local (to the cframe) angular offset.

If I can do this, I'm hoping I can use it to smoothly and accurately move the Character's Right Arm weld according to where you're looking/pointing.

Of which and how should I use these? Because I just keep getting Errors!

CFrame:toWorldSpace(CFrame cf) "returns a CFrame transformed from Object to World coordinates. Equivalent to CFrame * cf"

CFrame:toObjectSpace(CFrame cf) "returns a CFrame transformed from World to Object coordinates. Equivalent to CFrame:inverse() * cf"

CFrame:pointToWorldSpace(Vector3 v3) "returns a Vector3 transformed from Object to World coordinates. Equivalent to CFrame * v3"

CFrame:pointToObjectSpace(Vector3 v3) "returns a Vector3 transformed from World to Object coordinates. Equivalent to CFrame:inverse() * v3"

CFrame:vectorToWorldSpace(Vector3 v3) "returns a Vector3 rotated from Object to World coordinates. Equivalent to (CFrame - CFrame.p) * v3"

CFrame:vectorToObjectSpace(Vector3 v3) "returns a Vector3 rotated from World to Object coordinates. Equivalent to (CFrame:inverse() - CFrame:inverse().p) * v3"

1 answer

✓ Accepted answer

To answer directly, you will need to use the CFrame:pointToWorldSpace(Vector3) to get the direction you want. It returns the coordinates of the mouse hit as if the CFrame is 0,0,0

To more answer your question, to get the weld to "look" at the target, you will need to set the CFrame as such:

-- w = the weld you are using
w.C0 = CFrame.new(Vector3.new(offset), w.Part0:pointToWorldSpace(target))

The two arguments are the Vector3 offset and where it is going to look. The pointToWorldSpace is crucial because the Weld treats Part0 as the center of the world, not the 0,0,0 of Workspace.

You will also need to mess with the C1 in order to get the weld to behave properly; because, with only that one block of code, the arm will be rotating around the center of the arm, not at the elbow.

1 comment

0

I see, thanks for your help!

This discussion is preserved as it was. New answers, comments, and votes are closed.