While thinking about my last script, I realized this is likely a more efficient and accurate way to collect the movement data:
-- recording phase
local movedata = {};
local player = game.Players:WaitForChild('devmaxcat')
while not player.Character do wait() end
local last = nil;
local conn = player.Character:WaitForChild("Humanoid"):GetPropertyChangedSignal('MoveDirection'):Connect(function(moveDirection)
last = last or tick()
local t = tick() - last
table.insert(movedata, {
direction = player.Character.Humanoid.MoveDirection,
duration = t
})
last = tick()
end)
task.wait(3) -- record for 3 seconds
-- playback phase
conn:Disconnect()
table.insert(movedata, {
direction = Vector3.new(0,0,0),
duration = 0
})
for i in pairs(movedata) do
game.Workspace.Rig.Humanoid:Move(movedata[i].direction)
task.wait(movedata[i].duration)
end
I did some experimentation and this setup produced fairly decent results. I imagine it can be improved, since a task.wait is involved in the playback. If you need predetermined movement, you’ll need to get out the movedata array into something static and re-usuable.
Previous Code
-- recording phase
local movedata = {};
local player = game.Players:WaitForChild('devmaxcat')
local t = 0
local conn = game:GetService('RunService').Heartbeat:Connect(function(dt)
t += dt -- measures the duration of the movement
if not player.Character then return end
local moveDirection = player.Character.Humanoid.MoveDirection
if moveDirection ~= movedata[math.max(#movedata - 1, 1)] then
table.insert(movedata, {
direction = moveDirection,
duration = t
})
t = 0 -- we recorded the movement, so lets start recording the next movements duration
end
end)
task.wait(3) -- record for 3 seconds
-- playback phase
conn:Disconnect()
for i in pairs(movedata) do
game.Workspace.Rig.Humanoid:Move(movedata[i].direction)
task.wait(movedata[i].duration)
end
I made a small experiment recording the CFrame every single frame.
The movement is pretty accurate, however… since I’m saving the CFrame every frame, the recording table is made out of 700 CFrames only for 5 seconds of “animation”, which cannot not be good.
But either way you can see how would it look this way.