How to do algebra with CFrames?

I have this formula:

CenterPartWithArrows.CFrame = CFrame.new((part.ExtentsCFrame * CFrame.new(offsetPosition)).Position)

It works perfectly. However I need it to be in this form:

offsetPosition = ...

How do I isolate offsetPosition? Thanks!

making a new cframe of the existing cframe’s position is redundant
you can just do

CenterPartWithArrows.CFrame = (part.ExtentsCFrame * CFrame.new(offsetPosition)).Position

you can move part.ExtentsCFrame to the other side by multiplying by the inverse of the cframe

CenterPartWithArrows.CFrame * part.ExtentsCFrame:Inverse() = CFrame.new(offsetPosition)

Do you mean you want to set offsetPosition before that formula?
It looks like offsetPosition would be a Vector3 value and needs to be set that way.

the reason I’m doing that is so that the rotation is 0.

offsetPosition would be a vector3, correct.

Not quite:
I have an offset position saved
then I do the formula to the part
then the part goes through other processes
now that the offset position has been adjusted, I wanna re-save it.

Thanks!

At the beginning save the value of offsetPosition as a different variable (let’s call it offsetPositionNew).

offsetPositionNew = offsetPosition
-- code and calculations and processes on offsetPositionNew
offsetPosition = offsetPositionNew

then you can go back to the original variable for your next code.

the offset position gets adjusted… I would like it to be this simple though :joy:

.Position already gets rid of the rotation

True, but a CFrame can’t be set to a Vector3…

image

Yeah didn’t think so :p

Translating this slightly and removing “.CFrame”
CenterPartWithArrows = ZeroRotation(partExtents * offsetPositionCFrame)
Clearly removing the rotation is not reversible, so you cannot rewrite this equation the way you’ve requested. Can you draw a diagram of what CFrame you’re trying to create?

1 Like

What your problem really boils down to is you having a start and end position, and you wanting to know the offset between them in object-space.

This can be done with relative ease, and without the need of algebra. Simply use the VectorToObjectSpace method of CFrames.

local offsetPosition = part.ExtentsCFrame:VectorToObjectSpace(CenterPartWithArrows.Position - part.ExtentsCFrame.Position)

Yep, this works :D
Thanks!

30 сhаrасtеrs

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