Mirror character display?

My game has a tilt system where the character tilts in the direction it walks, and my game also has character viewport display thing where it shows the player’s character whenever their inventory is open, it all works fine but the problem is that the player’s display viewport is not mirrored, which makes it look weird when you walk.

I basically just want to mirror the character in the viewport.

Here is my current code that runs every frame:

for _, part in pairs(self.ViewportCharacter:GetDescendants()) do	
	if part:IsA("BasePart") then
		local realPart = nil

		for _, possiblePart in pairs(self.Character:GetDescendants()) do
			if possiblePart.Name == part.Name and possiblePart.Parent.Name == part.Parent.Name then
				realPart = possiblePart
			end
		end

		if realPart and part.Name ~= "HumanoidRootPart" then
			local relativeCFrame = realPart.CFrame:ToObjectSpace(self.Character.HumanoidRootPart.CFrame):Inverse()
			part.CFrame = self.ViewportCharacter.HumanoidRootPart.CFrame * relativeCFrame
		end
	end
end
1 Like

Found the solution! Here’s the method to mirror the cframe for anyone looking for it.

local relativeCFrame = realPart.CFrame:ToObjectSpace(plrCharacter.HumanoidRootPart.CFrame):Inverse()
local X, Y, Z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = relativeCFrame:GetComponents()

local mirrored = CFrame.new(
	X, Y, -Z,
	-R00, R01, R02,
	-R10, R11, R12,
	R20, -R21, -R22
)

viewportPart.CFrame = viewportCharacter.HumanoidRootPart.CFrame * mirrored

Here’s how it looks now:

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.