Dynamic animations

The game I’m currently working on randomly assigns character sizes per each run. The only problem is that I’m using skinned meshes (with bones and motor6ds) and animations need to be rescaled for rigs of different sizes. Since there are hundreds of possible sizes, it’s currently not effective for me to upload an animation for every single size possibility. As a result, I’ve forked OKevinO’s plugin for scaling animations with skinned meshes to use on the KeyFrameSequences during runtime, only to discover that running KeyFrameSequences is only possible on Studio and not in game.

Current code:

function Scaling:ScaleAnimation(Animations, Original, New)
	local Folder = Instance.new('Folder')
	local ScaleFactor = CalculateScale(Original, New)
	
	if not ScaleFactor then
		warn('Scale factor not present.')
		return
	elseif ScaleFactor <= 0 then
		warn('Scale factor too low.')
		return
	end

	for _, Animation in pairs(Animations) do
		if not Animation.ClassName == 'KeyframeSequence' then
			warn('Keyframe sequence not attributed.')
			continue
		end

		local NewAnimation = Animation:Clone()

		for _, Pose in pairs(NewAnimation:GetDescendants()) do
			if Pose:IsA('Pose') then
				Pose.CFrame = Pose.CFrame + Pose.CFrame.p  * (ScaleFactor - 1)
				NewAnimation.Parent = Folder
			end
		end
	end

	return Folder
end

Are there any other approaches I can take?

3 Likes

Your script is making new KeyframeSequences with the properly scaled positioning, but those need to be uploaded to the Roblox library to be baked into the traditional animations that you reference with Id and play in game.

You’ll may have to roll your own animation handler; this is how the animation plugins play back the KeyframeSequences in studio. You should still be able to load the KeyframeSequences via GetKeyframeSequenceAsync at runtime. It would need to update each rigs joint’s Motor6D.Transform property on the client, so you’ll need to handle network replication of play/stop via remotes. You would probably also want to implement the weighted animation blending for smooth transitions/overlays.

If your game design permits it: the simpler alternative could be limiting the range of your ScaleFactor. From my experimenting with scaled down characters, the roblox provided animation sets hold up until about .75-.5 scale, any smaller and it needs the animation’s position component scaled.

1 Like