# Calculate Mirror Position Over Tilted Axis

Hello gamers,
I’m trying to calculate the mirror position while placing objects in my tank editor scene. The tank (group of bubbles on the left side of the editor scene) moves to always be in the correct position to compensate for camera rotation and resizing. But this means that the axes I would like to mirror object positions over are not always straight. (So I can’t just mirror object placement over the axis by multiplying the value by -1)

I was able to make mirror placement over both vertical AND horizontal axes work:
syies2

``````objectsToPlace[3].position = new Vector3(editorCenter.x * 2f - placement.x, editorCenter.y * 2f - placement.y, 0f);
``````

Where editor Center is the center of the circle borders on the left side of the editor scene, and placement is the mouse position.

However, I have really struggled with how to make mirror positioning over JUST vertical OR horizontal axis.

If anyone could give some advice on how to calculate single-axis mirror positioning, that would be much appreciated!

-Thanks

I did some digging and found this formula you can use off of stackexchange which should be able to reflect a point across a line (supposing you know the formula for the line).

1 Like

Excellent! Thank you for finding this!

I was able to pull it off

y3slgu

I took a point directly horizontal to the editorCenter on screenspace, then found the formula of the line between the two points using https://www.geeksforgeeks.org/program-find-line-passing-2-points/
Then I put in (a, b, c) into the horizontal axis line in the way it would be used in the next formula:

Repeated above code for vertical axis ^

Then made the function with the formula you found from the link

And it works like a charm! I just update the horizontal and vertical axes whenever the camera changes and it does its ting

1 Like