-
What do you want to achieve?
We’re having a friendly Halloween competition inside a discord group I’m apart of.
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
Expectation:
(Yes, I know, I’m a terrible animator. This is kinda a proof of concept)
-
What is the issue?
Reality:
-
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.