Help on my mirror?

1I want to achieve an inverse effect for my mirror, everything is working fine but like it doesnt look like a really good mirror since it goes the other way when i go to the end of the mirror

  1. This is the issue:

    Hopefully no one minds that I have no clothes/accessory in the mirror, I am still working on it.
  2. Tried looking for some solutions but I haven’t find something related to my problem

That’s all I have to say, I’m a bit sure u only have to add 1-3 lines of code to fix this issue, but I’m never really good when it comes to math and formula stuffs, maybe :Inverse() could work out but I don’t know how to use it, I did try but nothing worked well

local mirror = workspace:WaitForChild('mirrors'):WaitForChild('mirror')
local viewport = game:GetService('Players').LocalPlayer.PlayerGui:WaitForChild('ScreenGui'):WaitForChild('SurfaceGui'):WaitForChild('ViewportFrame')
local cs = game:GetService("CollectionService")
local camera = Instance.new("Camera", viewport)
viewport.CurrentCamera = camera
camera.CFrame = (mirror.CFrame*CFrame.new(0, 1, 12))

local function getrandomized()
	local o = ''
	repeat o = o .. string.char(97+math.random(1, 28)) until string.len(o)>=25
	return o
end
local function isvalid(m)
	if (m:IsA("BasePart") or m:IsA('MeshPart')) and not m:IsDescendantOf(workspace.mirrors.mirror) and m.Archivable==true and not m:IsA("Terrain") and m.Name~='mirror' then
		return true
	end
end
local function addobject(m)
	if isvalid(m) then -- noob just checks if its a basepart
		local c = m:Clone()
		c.Parent = viewport
		c.Anchored = true
		c.CanCollide = false

		local o
		o = game:GetService("RunService").RenderStepped:Connect(function()
			local e, r=  pcall(function()
				if m.CFrame~=c.CFrame then
					c.CFrame = m.CFrame
				end
			end)
			if not e then
				c:Destroy()
				if o then 
					o:Disconnect()
				end
			end
		end)
		
	end
end
local function removeobject(m)
	if isvalid(m) then

	end
end

workspace.DescendantAdded:Connect(addobject)
-- workspace.DescendantRemoving:Connect(removeobject)
for _, v in pairs(workspace:GetDescendants()) do
	addobject(v)
end
game:GetService("RunService").RenderStepped:Connect(function()
	-- maybe camera stuffs
end)

I’m pretty sure theres nothing wrong with the viewportframe or anything outside the script, I just need the formula to inverse stuffs.

1 Like

You are cloning the Parts of the character, not the entire character

fortunatelly you need to use a function that i already have. You need to invert the X position (and orientation) but relative to the mirror cframe.

local mirror = workspace:WaitForChild('mirrors'):WaitForChild('mirror')
local viewport = game:GetService('Players').LocalPlayer.PlayerGui:WaitForChild('ScreenGui'):WaitForChild('SurfaceGui'):WaitForChild('ViewportFrame')

local camera = Instance.new("Camera", viewport)
viewport.CurrentCamera = camera
camera.CFrame = (mirror.CFrame*CFrame.new(0, 1, 6))

local world = Instance.new("WorldModel")
world.Parent = viewport

local function isvalid(m)
	if (m:IsA("BasePart") or m:IsA('MeshPart')) and not m:IsDescendantOf(workspace.mirrors.mirror) and m.Archivable==true and not m:IsA("Terrain") and m.Name~='mirror' then
		return true
	end
end

local function Bounce(ShotOriginPos)
	local Converted = mirror.CFrame:ToObjectSpace(ShotOriginPos)
	return mirror.CFrame:ToWorldSpace(CFrame.new(Vector3.new(-Converted.X,  Converted.Y, Converted.Z), Vector3.new(-Converted.X,  Converted.Y, Converted.Z) + Vector3.new(-ShotOriginPos.LookVector.X,ShotOriginPos.LookVector.Y,ShotOriginPos.LookVector.Z)))
end

local function addobject(m)
	if isvalid(m) then -- noob just checks if its a basepart
		local c = m:Clone()
		c.Parent = world
		c.Anchored = true
		c.CanCollide = false

		local o
		o = game:GetService("RunService").RenderStepped:Connect(function()
			local e, r=  pcall(function()
				if m.CFrame ~= c.CFrame then					
					c.CFrame = Bounce(m.CFrame)
				end
			end)
			if not e then
				c:Destroy()
				if o then 
					o:Disconnect()
				end
			end
		end)

	end
end
local function removeobject(m)
	if isvalid(m) then

	end
end

workspace.DescendantAdded:Connect(addobject)
-- workspace.DescendantRemoving:Connect(removeobject)
for _, v in pairs(workspace:GetDescendants()) do
	addobject(v)
	print"added"
end

game:GetService("RunService").RenderStepped:Connect(function()
	-- maybe camera stuffs
	
end)

I also tried to update the viewport camera cframe too look more realistic but it didnt worked out

1 Like

also the textures will appear if you use a worldModel as ive made in the script above. If the player have 3D clothes it will be a mess though

1 Like

tysm this helped a lot ! Doesn’t weirdly go the other direction when i do it now.

Can you add a screenshot of the result ? :slight_smile:

sure! its right here:
Screen Shot 2022-10-13 at 9.01.11 AM
I still haven’t add in the clothes tho

1 Like

it did solve the inversion but theres another problem. Theres an offset in the rotation and the arms look weird.

Hum it looks good except the arms and the clothes

If it’s the solution mark the post as the solution.

Uuuh yeah, i would neet to add the rotation change in the CFrame too but i dont know mutch about how to do that. I only inserted the lookvector and position

it is but it is only a part of the solution, not the entirety

1 Like

you see im only cloning parts since it’ll be more laggy once i insert stuffs like welds etc etc, physics problems