How would I mirror a part across a certain axis?

I want to know how to mirror a part across a certain axis.

Example (y axis - ignore translation)
image

The y axis is inverted, but how would I code that in?
Note:
This is not solved by adding 180 degrees to the rotation but inverting the y axis. As I want to mirror the part.

I know the :Inverse() function exists, but how could you do this without that?

This topic will also serve as a tutorial for other developers for the years to come. Enjoy!

2 Likes

give me a minute. i have an idea, i just want to test it out in studio.

2 Likes

If you need help debugging and such, I will be here to help with that.

2 Likes

to be clear, you want it like a mirror? so like you press a button and the buttons mirror on top of each other upsidedown? like in real like when you place a block on a mirror the block is mirrored liked so?

1 Like

I am making a building system for a game I have. I want the side that is opposite from the side the player is placing blocks to be reflected. If you look at this image:
image

The right side if reflected on the left side.
Edit:
(Across a certain axis)
(Not all axis at the same time)

1 Like

heres what i have so far, but i’m unable to find out, sorry

heres most of what i have tho:

function mirror(part)
	-- get values
	local currentPosition = part.Position
	local currentRotation = part.Rotation
	
	local mirroredPosition = Vector3.new(currentPosition.X, -currentPosition.Y, currentPosition.Z)
	
	-- mirror part
	local mirroredPart = part:Clone()
	mirroredPart.Size = part.Size
	mirroredPart.Position = mirroredPosition
	mirroredPart.Rotation = currentRotation
	mirroredPart.Parent = part.Parent
end

wait(2)
mirror(script.Parent.Part)
1 Like

Note that position does not have to be mirrored - I have already solved that. (but thanks for trying). Only the rotation has to be mirrored. Thanks for helping!

ofcourse, take care! sorry i couldn’t solve the issue. i’m actually a ui designer not a scripter.

I think I found a solution.

pivot = CFrame.new(
	(Vector3.new(pos.X,pos.Y+size.Y/2,pos.Z) * directionVector3)
) * CFrame.Angles(math.rad(rot.X), math.rad(-rot.Y), math.rad(-rot.Z))

This works for any object that is mirrored on both sides, like a wedge. But not a corner wedge. I can just apply an object specific offset to the mirrored side and get the intended results. Hopefully. Going to test now.

This plugin has a really good “mirror” feature, I guess you could go inspect the code to see how it’s done.

I do not see the code anywhere in the plugin?

Adding an offset does not work because it just messes up the other axis of rotation, so I will have to do more digging.

I know this reply is incredibly late, but take a look at this post.

I hope you find it helpful!