How to inverse a CFrame relative to another CFrame

I have a pretty bad understanding of CFrames and terminology, so bear with me.

The white part is the center cframe,
The red part is where the current cframe is,
The green part is the cframe I want to get to (it’s like the opposite of the red part)

How would I do this?

5 Likes


you want to inverse a cframe relatively to a given CFrame?

1 Like

Yup, I’m going to change the title to be more clear

is this it?

-- some CFrames
local WhitePart = CFrame.new()
local RedPart = CFrame.new()

-- RedPart:ToObjectSpace(WhitePart) is the same as RedPart * WhitePart:Inverse()
local GreenPart = WhitePart * RedPart:ToObjectSpace(WhitePart):Inverse()

Nope, just sets it to where the red cframe is (blue part is an indicator)

wait i will open studio to mess with it a little lol


seems to work if i will remove :Inverse()

-- some CFrames
local WhitePart = CFrame.new()
local RedPart = CFrame.new()

-- RedPart:ToObjectSpace(WhitePart) is the same as RedPart * WhitePart:Inverse()
-- this comment above has an error in it
local GreenPart = WhitePart * RedPart:ToObjectSpace(WhitePart)

I get this

image

i found what was wrong
image
RedPart:ToObjectSpace(WhitePart) is the same as RedPart:Inverse() * WhitePart
not
RedPart:ToObjectSpace(WhitePart) is the same as RedPart * WhitePart:Inverse()

1 Like

image
do you want to just get the position or exactly CFrame? because it kinda goes off using just CFrames
code below uses positions

local WhitePart = Vector3.new()
local RedPArt = Vector3.new()

local GreenPart = WhitePart - (RedPart - WhitePart)

-- which simplifies to

local GreenPart = 2*WhitePart - RedPart
2 Likes

I need to use cframes, because the white part should be able to be rotated

1 Like

image

image
ok so you want to reflect RedPart along WhitePart taking in count only the rotation of white part?
screenshots above take in count rotation of both parts

2 Likes

I got it to work, it feels a little bit hacky but I can always look for a better solution later. Thank you @V_ladzec for helping!

Here’s my code:

local relative = redCframe:ToObjectSpace(centerCframe):Inverse()
local rotx, roty, rotz = relative:ToOrientation()

relative = CFrame.new(
	-relative.Position, 
	Vector3.new(math.deg(rotx), math.deg(roty), math.deg(rotz)) -- You can make this negative if you want to flip rotation too, but in my case I dont want to
)


local flippedCFrame = centerCframe * relative

3 Likes

messed with them a little more and found a better way to do it incase you will need it

local WhitePart = CFrame.new()
local RedPart = CFrame.new()

local Relative = RedPart:ToObjectSpace(WhitePart) 
local GreenPart = RedPart * Relative.Rotation + 2 * Relative.Position

You can multiply the green part’s position by -1 which gives you a negative number and set the position to that, it that’s what you mean.

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