How to get CFrame of part relative to another part?

image
image
image

What I want to achieve, is for the “Position” to be the same for all three, just the rotation would be different. (0,0,0) for the first two, and (0,-30,0) for the second image.

Imagine the gray part is at the center of the world. I would use :ToObjectSpace, right? And so the red part would be at -2, 0, 1. Wrong. (at least for the bottom image) The CFrame it returns is for some reason 2.232, 0, 0.134 at 0, -30, 0.

Any suggestions? Should I use separate vector3’s for the position and rotation? Thanks!

If the position in object space is not anchored when rotating the red part, you have the wrong order. You’re probably doing RedCF:ToObjectSpace(GreyCF), which is incorrect. Keep in mind CF:ToObjectSpace actually accepts a tuple, so it’s helpful to remember you’re more likely to use a single point as your base, so the rest are what should be relative.

What does this mean?

You are correct, I am.

You lost me at the last sentence :sweat_smile:
May you explain this to me as if I’m five? Thanks!

You wanted to get the red part’s cf relative to the grey’s, which means rotating the red shouldn’t of moved the positional component (“anchored”, as you would of expected).

If rotating the red part moves it’s position relative to the grey part, it means you’re rotating the entire system (with the new code, if you rotate the grey part, the position will move; this is expected). So that means the system was centered red->grey, not grey->red.

Generally if it’s wrong it’s valid to just flip and check. But ToObjectSpace accepts a variable amount of CFrame to convert to a new system, so when using CF:ToObjectSpace(...), CF should be the basis for the system.

Thank you so much!!! This has been bothering me all day, literally! I can’t thank you enough :D :D :D

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