PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

AddPose

This function adds a Pose to the Keyframe by parenting it to the keyframe. It is functionally identical to setting the pose’s Instance/Parent to the keyframe.

Note, this function will not error when an instance other than a Pose is given as the pose parameter and will parent it successfully.

Parameters

Name Type Default Description

The Pose to be added.

Returns

Return Type Summary

Code Samples


Keyframe Add/Remove Pose

This sample demonstrates quickly the Keyframe.AddPose, Keyframe.RemovePose and Pose.AddSubPose and Pose.RemoveSubPose functions. Note these are functionally equivalent to parenting and un-parenting the poses.

local keyframe = Instance.new("Keyframe", workspace)

local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out

keyframe:AddPose(pose) -- pose.Parent = keyframe

wait(2)

keyframe:RemovePose(pose) -- pose.Parent = nil 

wait(2)

keyframe:AddPose(pose) -- pose.Parent = keyframe

wait(2)

pose:AddSubPose(pose2) -- pose2.Parent = pose

wait(2)

pose:RemoveSubPose(pose2) -- pose2.Parent = nil

Keyframe Generate Poses

This sample includes a function that will generate a ‘blank’ keyframe containing blank poses for all of the model’s connected parts in the correct hierarchical order.

    local function generateKeyframe(model)
    	if not model.PrimaryPart then
    		warn("No primary part set")
    		return
    	end
    	
    	local rootPart = model.PrimaryPart:GetRootPart()
    
    	if not rootPart then
    		warn("Root part not found")
    		return
    	end
    
    	local partsAdded = {}
    	partsAdded[rootPart] = true
    
    	local function addPoses(part, parentPose)
    		-- get all of the joints attached to the part 
    		for _, joint in pairs(part:GetJoints()) do
    			-- we're only interested in Motor6Ds
    			if joint:IsA("Motor6D") then
    				-- find the connected part
    				local connectedPart = nil
    				if joint.Part0 == part then 
    					connectedPart = joint.Part1
    				elseif joint.Part1 == part then 
    					connectedPart = joint.Part0
    				end	
    				if connectedPart then 	
    					-- make sure we haven't already added this part
    					if not partsAdded[connectedPart] then
    						partsAdded[connectedPart] = true
    						-- create a pose
    						local pose = Instance.new("Pose")
    						pose.Name = connectedPart.Name
    						parentPose:AddSubPose(pose)
    						-- recurse
    						addPoses(connectedPart, pose)
    					end
    				end			
    			end
    		end
    	end
    
    	local keyframe = Instance.new("Keyframe")
    
    	-- populate the keyframe
    	local rootPose = Instance.new("Pose")
    	rootPose.Name = rootPart.Name 
    	addPoses(rootPart, rootPose)
    	keyframe:AddPose(rootPose)
    
    	return keyframe
    end