Making a smooth pet system

Ok so right now im trying to create a pet follow system and while ive had a degree of success I am not pleased by my results. so currently what im doing in keeping a part relative to the player’s humanoidrootpart via renderstepped and then tweening the pet model up and down off that part which is giving me an result looking like this https://gyazo.com/3f179bda8d59d877a05b25336c150124

Im wondering how I can make the transition smoother with the pet following the player because right now it just feels like the pet is physically attached.

3 Likes

To make it simple and have you write less code, you could just put a BodyPosition inside the relative part. Then every game-tick, update the BodyPosition desired position to the prior relative position of the player. This will make your ‘pet’ feel ‘springy’ so that it doesn’t instantly move when you move.

2 Likes

would this work on models too?

2 Likes

Well, according to you, you are “keeping a part relative to the player’s humanoidrootpart via renderstepped and then tweening the pet model up and down”. It seems like all your part does is store a Vector3 position that the model is using for it’s tweening reference position. By doing what I instructed prior, all you are doing is just changing the reference part position in a different manner.

5 Likes

I would look into this for positioning the pet:
https://developer.roblox.com/en-us/api-reference/class/AlignPosition

Also, setting the pet’s NetworkOwner to the client would help everything look a lot smoother.
https://developer.roblox.com/en-us/articles/Network-Ownership

Ye, im already handling pets on client to allow player to have the option to see other player’s pets or not to support lower end devices

in RenderStepped when you update the part’s CFrame relative to the player’s CFrame, instead lerp it by 90% of so using the :Lerp method, and then apply the up/down tween translation afterwards. This’ll make it glide to follow the player but not feel like it is attached, and is a very simple change to make.

RunService.RenderStepped:Connect(function(dT)
    local NewCF = HumanoidRootPart.CFrame * PetOffset --offset of hover eg cf(3,5,5)
    Pet.RootPart.CFrame = Pet.RootPart.CFrame:Lerp(NewCF, .9) * TweenOffset
end)
1 Like

thx for the alternate method, however I will prob stick with @jody7777 since it is simplest and also greatly shortens my code. but thx for responding