I’m trying to improve a viewport frame mirror that I have.
The first version I have is this:
Basically, the mirror clones the characters of all players and then makes all their part’s CFrame the same as the player’s.
It’s a good base, but it isn’t inverted/reflected like a normal mirror. So I tried to invert the position and angles of the parts according to the mirror.
As you can see, it is almost perfect. If the arms angled themselves nicely, we wouldn’t be here.
But I don’t know why it’s doing this, nor do I know what exactly to do since it’s only really apparent on the arms.
Interestingly, though this is due to the mesh, the normal block roblox mesh character makes this less dramatic.
What do I do?
Code
local function reflectPositionOverAxis(position)
local dir = (position - mirPart.Position)
local dist = dir.Magnitude
dist = -dist*dir.Unit:Dot(mirPart.CFrame.RightVector.Unit)
local newOrigin = mirPart.Position + mirPart.CFrame.RightVector*-dist
local newPos = ((position - newOrigin) * -1) + newOrigin
return Vector3.new(newPos.X, position.Y, newPos.Z)
end
local function reflectCFrameOverAxis(cframe)
local pos = reflectPositionOverAxis(cframe.Position)
local lookat = reflectPositionOverAxis(cframe.Position+cframe.LookVector)
return CFrame.new(pos, lookat) -- why does this only work for the legs and the arms?
end