Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I create a still projection of the player?

Asked by
ka3r 14
4 years ago
Edited 4 years ago

How would I be able to clone the player and make the clone follow and copy what the player does? Like a mirror? However, unlike the mirror models available on ROBLOX, I only want the player to be cloned. Nothing else. I also want the clone to stay in a single position. Basically it'll still play moving animations like walking and jumping but it won't move in the X or Z position.

local Player = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(player)

    local children = game.Workspace:GetChildren()
    for i, child in pairs(children) do
        if child.Name == player.Name then
            local x = child
            while true do
                wait()
                x:Clone().Parent = player.PlayerGui:FindFirstChild('ViewportFrame', true)
                local y = game.Workspace:FindFirstChild('VPCam',true)
                y.CameraSubject = x
                wait()
                x:Destroy()
            end
        end
    end
end)

Basically I tried making a script which will wait for the player to join. Once joined, it'll clone it and parent it into a viewport frame. It will then destroy and clone a new one copying it's movements. However, I can't seem to get it to work.

TL;DR: I want to make a viewport frame that will clone and put the LocalPlayer in it, the clone will mimic the movement of the player.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I would like to do this but it would take too long, however, there is a model you can download here: https://devforum.roblox.com/t/rendering-the-character-with-a-viewportframe/241369/31

This is the code if for some reason it doesn't work for you:

local script inside the gui with the viewport frame:

--Boatbomber

--Services
local RunService        = game:GetService('RunService')
local UserInputService  = game:GetService("UserInputService")

--Localize
local instance,newRay   = Instance.new,Ray.new
local v2,v3,cf,udim2    = Vector2.new,Vector3.new,CFrame.new,UDim2.new
local insert,random,abs = table.insert,math.random,math.abs


local Player            = game.Players.LocalPlayer
local Character         = Player.Character or Player.CharacterAdded:Wait()


--Basic setup
local ViewPort          = script.Parent.ViewportFrame

--Settings
local Offset            = cf(0,1,-6)

--Create the viewport camera
local Camera        = instance("Camera")
    ViewPort.CurrentCamera  = Camera

local ValidClasses = {
    ["MeshPart"] = true; ["Part"] = true; ["Accoutrement"] = true;
    ["Pants"] = true; ["Shirt"] = true;
    ["Humanoid"] = true;
}

local function RenderHumanoid(Model, Parent, MainModel)
    local ModelParts = Model:GetDescendants()
    for i=1, #ModelParts do
        local Part      = ModelParts[i]

        if ValidClasses[Part.ClassName] then

            local a         = Part.Archivable
                Part.Archivable = true

            local RenderClone   = Part:Clone()
                Part.Archivable = a

            if Part.ClassName == "MeshPart" or Part.ClassName == "Part" then
                PartUpdater = RunService.Heartbeat:Connect(function()
                    if Part then
                        RenderClone.CFrame = Part.CFrame
                    else
                        RenderClone:Destroy()
                        PartUpdater:Disconnect()
                    end
                end)
            elseif Part:IsA("Accoutrement") then
                PartUpdater = RunService.Heartbeat:Connect(function()
                    if Part then
                        if RenderClone.Handle then
                            RenderClone.Handle.CFrame = Part.Handle.CFrame
                        end
                    else
                        RenderClone:Destroy()
                        PartUpdater:Disconnect()
                    end
                end)
            elseif Part.ClassName == "Humanoid" then
                --Disable all states. We only want it for clothing wrapping, not for stupid @$$ performance issues
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.FallingDown,         false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Running,             false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics,    false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Climbing,            false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics,   false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Ragdoll,             false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.GettingUp,           false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Jumping,             false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Landed,              false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Flying,              false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Freefall,            false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Seated,              false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,    false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Dead,                false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Swimming,            false)
                RenderClone:SetStateEnabled(Enum.HumanoidStateType.Physics,             false)
            end

            RenderClone.Parent = Parent
        end 
    end
end


--Let the world load before starting
wait(1)


local function Render()
    ViewPort:ClearAllChildren()
    --Render the character
    local Char = instance("Model")
        Char.Name = ""
        Char.Parent = ViewPort
    RenderHumanoid(Character,Char)
end

--Handle changes
Character.DescendantAdded:Connect(Render)
Character.DescendantRemoving:Connect(Render)

--Initialize
Render()

CameraUpdater = RunService.Heartbeat:Connect(function()
    if Character.HumanoidRootPart then
        Camera.CFrame =  cf(Character.HumanoidRootPart.CFrame:toWorldSpace(Offset).p, Character.HumanoidRootPart.CFrame.p)
    end
end)
0
Thanks, this is what I needed. However, do you know how I could make it where when the player can hold down the LeftMouseButton and move it around in order to also move the character around? So they can see the back, side, ETC? ka3r 14 — 4y
0
Unfortunately, I do not know how to do that. I could look into it in the future and reply if I do find a way to do that. AntoninFearless 622 — 4y
0
Okay, thanks for telling me. For now I'll look into the script and see what alterations I need to be able to do it. ka3r 14 — 4y
Ad

Answer this question