ToObjectSpace help!

What I’m attempting to do is to transfer the grey part’s relative to the red brick. The object’s relative position will stay the same, however the global position changes. Here’s what I mean:


It works, right? Yes, but for wedges, it tells a different story.

I apologize for the hideous sketches.


efejsngef

Is there any solution?

You could just make the redbrick PrimaryPart of a model, and use :setprimarypartCFrame
Also you could weld them

But if you really want to do it like this,

local offset = redCFrame-greenCFrame

red.Moved:connect(function()
green.CFrame = red.CFRame * offset
end

If I moved a model with lots of parts, will it lag?

Don’t think so, if you’re CFraming it that should be good.

I tried with a bunch of parts, didn’t seem to work sadly.

Did you do primarypart? That one should definitely work.

I did ToPivot, but I never tried primarypart. I’ve always seen how ToPivot was more performant than primarypart, I could be lying.

Worth a try, no? Better to have a laggy script than a broken script

I actually found the solution!

local relativeCF = workspace.Origin.CFrame:ToObjectSpace(workspace.RandomPart.CFrame)
local globalCF = workspace.OtherOrigin.CFrame * relativeCF

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