I'm trying to animate a fluid motion of a pet following me. Sorry if the code looks poorly constructed, I am new to Lua (however do have lots of experience programming in other languages). Essentially, the pet will follow but appears to stutter (just very slightly, but enough to upset the eye). This is an effect that is not replicated in all servers which contain pets or other moving objects. Here is the code for its movement (very simple currently, just meant to bounce up and down, twist a bit, and always look and move towards its destination):
Once again, thanks!
repeat wait() until script.Parent.Owner.Value ~= "n/a" print("Pet spawned for "..script.Parent.Owner.Value.."!") local orientation = 0 local sway = 1 local pet local destination local owner local speed local function load() pet = script.Parent owner = game.Workspace[pet.Owner.Value] destination = owner.HumanoidRootPart.Position speed = pet.Speed pet.PetPart.Position = destination while true do runTick() wait() end end local function moveTick() if sway == 1 then orientation = orientation + 8 else orientation = orientation - 8 end if orientation > 90 then orientation = 85 sway = -1 end if orientation < -90 then orientation = -85 sway = 1 end local dx = destination.X - pet.PetPart.Position.X local dz = destination.Z - pet.PetPart.Position.Z local dist = math.sqrt(math.pow(dx, 2) + math.pow(dz, 2)) -- Look at destination (Y) and twists on jump (X) pet.PetPart.Orientation = Vector3.new(20 * math.sin(math.pi*(orientation/180)), 270 + 180*(math.atan2(dx, dz)/math.pi), pet.PetPart.Orientation.Z) -- Starts newVel with just the jump animation local newVel = Vector3.new(pet.PetPart.Position.X, 17 + 0.5 * math.abs(math.sin(math.pi*(orientation/180))), pet.PetPart.Position.Z) -- If not too close, approaches destination if dist > 4 then newVel = newVel + speed.Value*Vector3.new(dx/dist, 0, dz/dist) end pet.PetPart.Position = newVel end function runTick() if pet == nil then return end moveTick() destination = owner.HumanoidRootPart.Position end load()