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
Hopefully no one minds that I have no clothes/accessory in the mirror, I am still working on it.
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.
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
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