How do I make an illusion using SurfaceGuis and ViewportFrames?

I want to make the Viewport model stand next to the real one

(I know It will render infront of the table but that’s not the point)

Here’s a video for a better showcase

I don’t know what else to try, like I’m desperate, I’ve fallen so low to the point I even asked ChatGPT
And funnily enough the attempt you see in the video is what ChatGPT gave me, it looked even better than my OWN closest attempt so

I’ll leave the code I tried for both attempts (My best one, and GPT’s)

GPT’s:

game["Run Service"].RenderStepped:Connect(function()
		local mainCamera = workspace.CurrentCamera

		local relativePosition = Parent.CFrame:PointToObjectSpace(mainCamera.CFrame.Position)
		self.CamVPF.CFrame = Parent.CFrame * CFrame.new(relativePosition)

		self.CamVPF.CFrame = self.CamVPF.CFrame - self.CamVPF.CFrame.Position + mainCamera.CFrame.Position
		self.CamVPF.CFrame = CFrame.new(self.CamVPF.CFrame.Position) * CFrame.Angles(mainCamera.CFrame:ToEulerAnglesXYZ())
	end)

My best attempt:

game["Run Service"].RenderStepped:Connect(function()
		local lol1, lol2, lol3 = workspace.CurrentCamera.CFrame:ToEulerAnglesXYZ()
		
		self.CamVPF.CFrame = CFrame.new(self.GUI.Adornee.Position) * CFrame.Angles(lol1, lol2, lol3)
	end)
I’ve been stuck on this for like 3 weeks now please help
4 Likes

Hello!

Before I look into your problem excessively, why exactly do you want this view port to be there? Is it not possible for you to copy the dummy and size it down?

1 Like

You are using a ScreenGui, right? All you need to do is set ViewportFrame.CurrentCamera to workspace.CurrentCamera in your Script, and enable ScreenGui.IgnoreGuiInsets.

2 Likes

@CC_KevinDev It’s in the title, knowing how to do this with viewport frames will allow me to do some cool tricky illusions, the dummy and the house are just an example experiment with this

@Judgy_Oreo As I mentioned I’m using a SurfaceGui, which is located on an invisible part right at the door

try putting the surface gui into the player gui and setting the adornee to the part.

That is quite literally exactly what I’m doing.

The issue is updating the camera’s CFrame so it looks correct relatively to the part’s position.

It is infinitely more complicated to use a SurfaceGui, you need to make a Portal for that.

Can you explain what you’re trying to do? What effect are you trying to get from the Viewport Frame?

Can you explain what you’re trying to do? What effect are you trying to get from the Viewport Frame?

I want to have the Viewport model, stand next to the real one, as in updating the Viewports Camera’s CFrame to match how it should look from my POV, like in the Portal example you showed me.

If all the math in the example is necessary I might just quit

Ok, but why? I’m asking what effect you’re trying to achieve, not how you’ve decided to achieve it. Maybe there’s some other way to do it, without using Viewports.

It’s a challenge for myself, the idea is to make something with the Viewport, so I can learn.

ByteBlox has made a few videos detailing illusions with Viewport Frames.

This is completely unrelated to the post and I will get warned for this but byteblox is a racist. here is proof: https://www.youtube.com/watch?v=0ekXwMzAxE0