My code previously:
local plr = game.Players.LocalPlayer
local plrs = game:GetService("Players")
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local copy
local vf = script.Parent
local vfc = Instance.new("Camera")
vfc.Parent = vf
local idleAnim
local d = Instance.new("Model")
d.Parent = workspace
local anims = script.animations
local part = workspace.Part
local rs = game:GetService('RunService')
local rp = Enum.RenderPriority.Last.Value
vf.CurrentCamera = vfc
d.Name = plr.Name
wait(2)
for k,v in pairs(char:GetChildren()) do
v:Clone().Parent = d
end
d.PrimaryPart = d:FindFirstChild('HumanoidRootPart')
spawn(function()
local dHum = d:FindFirstChild('Humanoid')
idleAnim = anims:WaitForChild('idle')
idleAnim = dHum:LoadAnimation(idleAnim)
idleAnim:Play()
d:MoveTo(part.Position)
copy = d:Clone()
copy.Parent = vf
vfc.CFrame = d.HumanoidRootPart.CFrame*CFrame.new(0,0,-5.5,0,1,0,0)
end)
rs:BindToRenderStep("UpdateVPCharacter", rp, function()
local realCharacter = d
if realCharacter and copy then
for _, descendant in pairs(copy:GetDescendants()) do
if descendant:IsA("Motor6D") then
local realMotor = realCharacter:FindFirstChild(descendant.Name, true)
if realMotor then
descendant.Transform = realMotor.Transform
end
end
end
end
end)
Gives an output of:
https://gyazo.com/65216afd84b4d4bcdd82cb47afac762e
Which I am not wanting. My desired output from this code is to have the dancing figure to be displayed on the ViewportFrame.
I appreciate all and any help I receive or had received.
2 Likes
What about directly setting the CFrame for the parts of the cloned character instead of updating the Motor6Ds?
2 Likes
You need to use CFrame to animate parts in ViewportFrames because they don’t have any physics.
6 Likes
That leaves me confused though, why would I need to use CFrame and not Motor6Ds? I thought Motor6Ds are used for character movement? Also, could I just edit my code, or would I need to create a new concoction?
ViewportFrames are basically rendering another Workspace. However, they do not run any physics calculations in order to increase performance. Motor6Ds rely on physics, so they won’t work in ViewportFrames. CFrame is an actual property of the part, and thus can be changed even if there are no physics.
For your dance to work, you’re going to need to come up with something that uses CFrame to move instead of Motor6Ds.
2 Likes
Hm, alright. Am I not able to use the animation, or do I need to animate through CFrame.
1 Like
Theoretically, you could have two rigs: one in Workspace, and one the the ViewportFrame. You could play the animation in the Workspace rig and then copy each part inside its’ CFrame to the ViewportFrame rig every render step or something.
Here’s some sample code I quickly made that should do that:
--Make sure you're playing the animation in rig1.
local rig1 = game.Workspace.Rig
local rig2 = ViewportFrame.Rig
game:GetService("RunService").RenderStepped:connect(function()
local rig1descendants = rig1:GetDescendants()
local rig2descendants = rig2:GetDescendants()
for i = 1, #rig2descendants do
if rig1descendants[i] then --Just in case.
rig2descendants[i].CFrame = rig1descendants[i].CFrame
end
end
end)
For that to work, you will probably need to adjust the CurrentCamera of your ViewportFrame so you can actually see the rig, because chances are rig2 will be hidden somewhere far off the map.
3 Likes
Well currently I have it set up like that, I have the actual rig(player model), a dummy model(the animated one in workspace on the part), and then finally the copied dummy(the still one in the viewport). Would this setup work?
1 Like
The
rig2descendants[i].CFrame = rig1descendants[i].CFrame
outputs an error: CFrame is not a valid member of Vector3Value
.
@Intended_Pun
1 Like
Check to make sure the descendant is a BasePart before you try setting its CFrame, sorry.
2 Likes