Why are my custom animations slow?

  1. What do you want to achieve?
    We’re having a friendly Halloween competition inside a discord group I’m apart of.
    :jack_o_lantern:
    I’m trying to make a horse that can run on ScriptBuilder or any other game for that matter.
    As such, I can not rely on Roblox’s default Animation object.
    I’m trying to make a custom function that can play a KeyFrameSequence
    :upside_down_face:
    Expectation:
    (Yes, I know, I’m a terrible animator. This is kinda a proof of concept)

  2. What is the issue?
    Reality:

  3. What solutions have you tried so far?
    I’ve tried two different ways to ease the animations.
    First way is by lerping

ongoingTransforms = {}

local steppedRun = game:GetService('RunService').Stepped

function ease(speed,firstCF,lastCF,motor,increment)
	speed = speed*.5
    ongoingTransforms[motor] = false
    increment = 1/(speed*59)
    for number = 0, 1, increment do
        steppedRun:Wait()
        motor.Transform=firstCF:lerp(lastCF, number)
    end
    ongoingTransforms[motor] = true
    while ongoingTransforms[motor] and steppedRun:Wait() do
         motor.Transform = lastCF
    end
end

The second way is by trying to use TweenService




loopingMotors = {}

function playOnMotor(motor,cframe,speed)
	
	if not loopingMotors[motor] then
		
		loopingMotors[motor] = Instance.new('CFrameValue')
		loopingMotors[motor].Value = motor.Transform
		
		game:GetService('RunService').Stepped:connect(function()
			motor.Transform = loopingMotors[motor].Value
		end)
		
	end
	
	local TweenService = game.TweenService
	 
	local goal = {}
	goal.Value = cframe
	 
	local tweenInfo = TweenInfo.new(speed,
									Enum.EasingStyle.Circular )
	 
	local tween = TweenService:Create(loopingMotors[motor], tweenInfo, goal)
	
	tween:Play()

end

Both of those methods basically resulted in the same thing.

I’ve also tried using spawn() to multitask different parts of the code.

I couldn’t get any improvements.

You’re free to check out the full code for yourself, but I must warn you that while the code is not completely illegible, I never intended for anyone other than myself to look through it.

Also, as a side note, I know that Motor6D.Transform does not replicate.
To get by that, I’m probably going to have the animation script be a localscript that is given to every player by a modulescript.

Here’s just the code:
https://pastebin.com/raw/nGVMWZfj

Here’s a .rbxm file that contains the horse and the code:
dispeller’s Epic Horse.rbxm (11.8 KB)

Helpful informational links:
https://developer.roblox.com/en-us/api-reference/class/KeyframeSequence
https://developer.roblox.com/en-us/api-reference/class/Keyframe
https://developer.roblox.com/api-reference/class/Pose

Thank you for reading! Any positive feedback would be appreciated.
:grin:

3 Likes

I am not very experienced with animating, but have you tried using a very small number for the speed variable in the TweenService example?

Side Note: I am pretty sure spawn() has a built in 0.3 second delay so I would use coroutines instead.

2 Likes

Thanks for the suggestion.
I tried using coroutines but to no effect.

I’ve made some minor progress.
(And a new animation)

Expectation:

Reality:

Not sure what animator plugin your using, but maybe try using the Beta version of the plugin that got released like a week ago? Lots of useful features in it.

1 Like

I’m using the one that’s in Roblox studio by default.
The animator plugin shouldn’t make a difference.
What I’m trying to do is play a KeyframeSequence directly without the use of an Animation object.

EDIT: misplaced word

1 Like

I think that the issue is that it’s doing this really fast

Whereas the normal animation is doing all the Poses all at once…

I think I’m just not multithreading the poses properly…

Also, I’m going to edit the main post to include links to things that might be informational

1 Like