Copying an animation using cframes

i’m not sure if i am doing this correctly but i had an idea to replicate a player’s arm movements in a viewmodel using cframes and updating it every frame but i don’t know how to make the arms move like the physical arms

local players = game:GetService("Players")

local runservice = game:GetService("RunService")

local localplayer = players.LocalPlayer
local camera = workspace.Camera

localplayer.CharacterAdded:Connect(function(character)
	while not character:FindFirstChild("HumanoidRootPart") do
		wait()
	end
	
	local viewmodel = Instance.new("Model")
	local humanoid = Instance.new("Humanoid", viewmodel)
	
	for _, v in pairs(character:GetChildren()) do
		if v:IsA("BasePart") then
			if v.Name == "HumanoidRootPart" or v.Name == "Left Arm" or v.Name == "Right Arm" then
				local clone = v:Clone()
				clone.Parent = viewmodel
				
				for _, v in pairs(clone:GetChildren()) do
					v:Destroy()
				end
			end
		end
	end

	viewmodel.PrimaryPart = viewmodel:FindFirstChild("HumanoidRootPart")
	viewmodel.Parent = workspace.Camera
	
	runservice.RenderStepped:Connect(function()
		viewmodel.PrimaryPart.CFrame = camera.CFrame
	end)
end)

Use CCDIKController for inverse kinematics, you could use IKControl but seems to work on R15.

In order to replicate the arm movements in the ViewModel, you can align the CFrame of the arm parts in the ViewModel with the CFrame of the corresponding arm parts in the character model. You can update this alignment every frame, as you’re currently doing with the HumanoidRootPart.

local players = game:GetService("Players")
local runservice = game:GetService("RunService")
local localplayer = players.LocalPlayer
local camera = workspace.CurrentCamera

localplayer.CharacterAdded:Connect(function(character)
    while not character:FindFirstChild("HumanoidRootPart") do
        wait()
    end
    
    local viewmodel = Instance.new("Model")
    local humanoid = Instance.new("Humanoid", viewmodel)
    viewmodel.Parent = workspace.Camera
    viewmodel.PrimaryPart = viewmodel:FindFirstChild("HumanoidRootPart")
    
    local characterParts = {}
    local viewmodelParts = {}
    
    for _, part in pairs(character:GetChildren()) do
        if part:IsA("BasePart") then
            if part.Name == "HumanoidRootPart" or part.Name == "Left Arm" or part.Name == "Right Arm" then
                characterParts[part.Name] = part
                
                local clone = part:Clone()
                clone.Parent = viewmodel
                viewmodelParts[part.Name] = clone
                
                for _, child in pairs(clone:GetChildren()) do
                    child:Destroy()
                end
            end
        end
    end
    
    runservice.RenderStepped:Connect(function()
        for partName, characterPart in pairs(characterParts) do
            viewmodelParts[partName].CFrame = characterPart.CFrame
        end
    end)
end)

In this code, I’ve created two tables: characterParts and viewmodelParts. The keys in these tables are the names of the parts (“HumanoidRootPart”, “Left Arm”, “Right Arm”), and the values are the corresponding parts in the character model and the ViewModel.
In the RenderStepped function, I’ve iterated over the characterParts table and set the CFrame of each corresponding part in the ViewModel to match the CFrame of the part in the character model. This will keep the parts in the view model aligned with the parts in the character model, replicating the arm movements.

wow thanks!! it works really well! what if i wanted to “attach” the arms to the camera as well as the animations

1 Like

To Replicate Movement of a Animation, use Motor6D.Transform.

Very Simple, doesnt require that much effort.

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