Hello, recently I have been making a pet that follows the player with a little floating animation but I can’t make it less brutal when going down here is what I mean:
It goes up slowly but when it’s going down it goes down really fast how do I fix this? Here is my code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
wait(3)
local pet = game.ReplicatedStorage.Pet:Clone()
pet.Parent = workspace
local bg = Instance.new('BodyGyro', pet)
local bp = Instance.new('BodyPosition', pet)
local Drift = .08
game:GetService('RunService').Heartbeat:Connect(function()
Drift += .01
if Drift >= 2 then Drift = .08 end
local pos = char.HumanoidRootPart.CFrame + Vector3.new(4,Drift,4)
bg.CFrame = char.HumanoidRootPart.CFrame
bp.Position = Vector3.new(pos.x,pos.y,pos.z)
end)
end)
end)
I think its because your setting drift to .08 after it reaches two, which is would be weird since it would go down to .08 instantly rather than in a smooth motion, try implementing Drift -= 0.1 maybe
if Drift >= 2 then Drift -= 0.1 end
if Drift <= 0.9 then Drift += 0.1 end
You’re supposed to change the BodyPosition/BodyGyro values and not directly the pets value, and here:
This wouldn’t be needed. (I think?) You should have a loop for handling going up and down and one heartbeat or something to handle player position etc.