Hello,
I’m working on creating a custom humanoid :MoveTo() functionality. This is in hopes to remove the humanoid from my NPC characters and alleviate any unnecessary overhead of humanoids to optimize on performance.
The way I’m implementing this is by Tweening the rig’s root part to a predetermined location. The animations happen locally to ensure that they look smooth and also to lessen the load on the server. I’m running animations through an AnimationController.
This works for the most part except for one small issue where the rig basically jitters when moving. I suspect that this is caused because the movements/adjustments of parts done by the animation are overlapped with the tweening process which doesn’t look clean. Is there a different approach to solve this issue?
while wait(math.random(3)) do
ind = math.random(#destinations) -- randomly choose a destination (these are parts)
local target = destinations[ind]
local dist = math.sqrt(math.pow(target.Position.X - root.Position.X,2) + math.pow(target.Position.Z - root.Position.Z,2)) -- calculate distance
local waitToStop = dist / 12 -- calculate wait, the 12 would be in studs per second
-- Creating CFrame based on lookVector to find the appropriate angles to rotate the model
local rot = CFrame.new(root.Position, Vector3.new(target.Position.X, root.Position.Y, target.Position.Z))
radX, radY, radZ = rot:ToOrientation()
local rotate = TweenService:Create(root, TweenInfo.new(1,Enum.EasingStyle.Sine), {CFrame = rot})
rotate:Play()
-- The state is a string value found inside the rig
state.Value = "Walk"
wait(1)
print("Moving to "..target.Name..ind)
-- Calculating final position and tweening the model
local fin = CFrame.new(target.Position.X, root.Position.Y, target.Position.Z) * CFrame.Angles(radX, radY, radZ)
local tween = TweenService:Create(root, TweenInfo.new(waitToStop, Enum.EasingStyle.Linear), {CFrame = fin})
tween:Play()
wait(waitToStop)
-- Updating state
state.Value = "Stop"
end
Below is what I am running locally.
local rig = workspace:WaitForChild("Cougar1")
controller = rig.AnimationController
anim = controller:LoadAnimation(rig.Walk)
anim.Looped = true
anim.Priority = Enum.AnimationPriority.Movement
local state = rig:WaitForChild("State")
state.Changed:Connect(function()
if state.Value == "Walk" then
anim:Play()
else
anim:Stop()
end
end)
This video shows the jitter quite well : https://gyazo.com/ce1be8c15692463b91d8d76a9786e6e2
I’ve resolved that it’s an issue with the Tween (not the animation), but I’m not sure how to proceed or fix the Tween to be smoother