How did this game make their pets so smooth moving and lively?

They appear to be moving up and down, but also just tilting back and forth. The tweenservice will do both of those with mathematical graduations. Heheh, like snorebear just said.

3 Likes

If you make all of the highly visual aspects of your game (like animated objects and projectiles) animated completely client-sided, they will always look very smooth. Those are the perks of offloading animations/visuals to the clients instead of doing it all on the server or the network owner of the pets.

Alright i’ll do my effects client side. Problem is that I still have no idea how to replicate the motion of the pet. Somehow i’m supposed to use tweenservice and moveto magic with humanoids :frowning: .

You could animate the pets entirely by cframe if you really wanted to by using lerp and sine waves. Also, the pets dont have to be perfectly accurate on all systems. They just need to be roughly in the same place.

1 Like

Animating entirely by cframe sounds good. But how :frowning: Theres like a tilt and bobbing motion plus the pet follows the motion of the character. I cannot fathom how to apply all three of these at once. If I weld the pet then it can’t do the bobbing.

local c = cos(2 * time() + i)
pet.CFrame = pet.CFrame:Lerp(
    attachCFrame * CFrame.Angles(-c, 0, 0) + Vector3.new(0, c * 2, 0),
    0.1
)

You can also just make a repeating / looping tween or something. Whatever works really

3 Likes

My brain is currently too small to understand CFrame:Lerp im gonna go make it bigger and report back

Wait whats attachCFrame supposed to be

It interpolates from one CFrame to the other by using a percentage.
You can visualize it by taking a point and at 0% its at the start of a line, at 100% its at the end of the line, and at 50% its halfway between the start and end.

local function lerp(a,b,c) return a + (b - a) * c end

print(lerp(5, 10, 0)) --5
print(lerp(5, 10, 1)) --10
print(lerp(5, 10, 0.5)) --7.5
1 Like

is attachCframe the rootrigattachment?

It is wherever the pet should attach to. Usually, some point around the player.
https://i.gyazo.com/5fd902a2f7e811874cd79a949edaacbd.mp4

ok so lemme get this straight

I wanna weld some part to the character, this part’s cframe is gonna be attachCFrame. Then I lerp from that cframe according to the cosine function thingy you wrote. Idk what the i variable is for

The i variable is just for the index of the pet, as you will probably do this for all pets. This will make them have a sort of wave-like motion because each pet will be offsetted.

https://gyazo.com/88d781647d639ec7b9276a13dfb6e783

yooo i got something going on!

try using sin() instead of cos() for the tilting and add like 0.1 to it so sin(2 * time() + i + 0.1)

1 Like

I would use RenderStepped with a lerp instead of tweenservice. Using the step argument. Something like

game:GetService("RunService").RenderStepped:Connect(function(Step) 
      Pet.CFrame = Pet.CFrame:Lerp(Base.CFrame * CFrame.new(0, 0.66 * math.sin(tick()), 0), Step) 
end)
3 Likes

isnt that the same thing just slightly shifted in the x direction

Yes but if you look at the curves for sine and cosine you will see why i made the switch.

Tween Service allows for customization, such as different easing styles.

2 Likes

Am i supposed to make a new tween every heartbeat or something? Is that costly for the client? @Luacrative solution is giving me the effect I want and I think it wont have noticeable performance cost.

No, with Tween Service, you can just make a new tween for every time the player moves. Here’s how I’d do it:

  • Constantly playing animation for the pet to move up, down, tilt side-to-side, etc.
  • Tween Service used to create a smooth movement from the original position to the new position as determined the by the CFrame offset of the player.

Now I know “CFrame offset” sounds scary but it’s really just:

petHRP.CFrame:toObjectSpace(playerHRP.CFrame); -- HRP = Humanoid Root Part

-- This is the equivalent to playerHRP.CFrame - petHRP.CFrame which just gives you the CFrame offset of the pet's HRP to the player's.