Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can anyone exlplain inversing to me, like CFrame:inverse, and etc?

Asked by 6 years ago

Does inversing return the original position of an object? or what, thank you for answering if you do!

1 answer

Log in to vote
5
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
6 years ago

In math, the inverse of a value with respect to some operation is the value that "undoes" the operation.

For example, the additive inverse of 5 is -5 since 5 + -5 = 0. If you have x + 5 + -5, you get back x.

The multiplicative inverse of 5 is 1/5, since 5 * 1/5 = 1. If you have x * 5 * 1/5, you get back x.

In Roblox, the :inverse() of a CFrame can be used to "undo" a multiplication of a CFrame. Normally, the inverse itself is useless. An easier to grasp pattern uses the :toObjectSpace method.


The .CFrame of a part is absolute, that is, it's "relative" to the origin, some fixed point in the middle of the map.

Often, you want to know how two parts are related in space. For example, how far above part A is part B?

You can use a.CFrame:toObjectSpace(b.CFrame) to get the position and orientation in space of b relative to a. Internally, this is just a.CFrame:inverse() * b.CFrame.

One application of this is simulating joints:

-- Capture how `part` was originally placed relative to `anchor`
local offset = anchor.CFrame:toObjectSpace(part.CFrame)

while wait() do
    -- Spin the anchor somehow
    anchor.CFrame = anchor.CFrame * CFrame.Angles(0.1, 0.2, 0.3)

    -- Keep `part` in the same place relative to the anchor as it was before
    part.CFrame = anchor.CFrame:toWorldSpace(offset)
end
0
This is the info that i searched for hours thank you so much!!! Volt3Z 40 — 6y
Ad

Answer this question