Mirror Script Help mee

I’ve seen a couple games manage to pull off a semi-realistic mirror through cloning characters. But i’m confused on how to properly match the location and orientation, along with the animation in the mirror.

I tried writing this:

wait(3)
    while true do
    wait()
    players = game.Players:GetChildren()
    for i=1, #players do
    local ccc = players[i].Character
    players[i].Character.Archivable = true
    newww = ccc:Clone()
    newww.Parent = workspace
    newww.HumanoidRootPart.CFrame = script.Parent.CFrame + (script.Parent.Position -ccc.HumanoidRootPart.Position)
    wait()
    newww:Remove()
    end
    end

But it just leaves a flashing, unanimated, unrotated, character on the other side of the mirror. It also places the character on the opposite side horizontally.

4 Likes

There is a new way to do this. I am unsure if they have pushed it to the actual game, but here’s a thread that can do basically what you want to do

1 Like

Your characters are flashing because you use :Remove()/:Destroy() every time you update the scene.
To achieve this, you need to clone the entire character’s model, remove all of the scripts within, destroy all joints, change the model’s name to an empty string and make every single part anchored. Then you need to orientate the part exactly on the opposite side of the mirror’s plane.

I found an interesting article on this topic from way back when:

https://devforum.roblox.com/t/could-somebody-explain-why-this-math-works/22304

The gist of what he’s saying:

local mirrorCF = --mirror cframe
local char = --character
local components = {(char:GetPrimaryPartCFrame():Inverse() * mirrorCF):GetComponents()}

--[[
-px, py, pz,
 xx,-yx,-zx,
-xy, yy, zy,
-xz, yz, zz
--]]
for _,i in ipairs{1,5,6,7,10} do
    components[i] = -components[i]
end

copy:SetPrimaryPartCFrame(mirrorCF * CFrame.new(unpack(components)):Inverse())

I know the mechanisms behind how this works, I just don’t know enough about inverse CFrames to explain it…

I hope that helps.

2 Likes

You could use ViewportFrame to make that.

It would be helpful to explain what you have in mind. Linking an object doesn’t really do much in terms of trying to find a solution.

I use the code linked here:
https://wiki.unity3d.com/index.php/MirrorReflection3
It’s for Unity, so no Lua, but the only component of it you need to achieve this is “CalculateReflectionMatrix” at the very end.