"Pet Simulator X"-esque Pet Movement

I’m trying to make a pet system which moves the pet down to the ground instead of floating so it can walk naturally. I’ve searched for ways to do this but came up with nothing, does anybody have any suggestions?

Example of the pet movement I want to achieve:
https://gyazo.com/5f33220bdbb0e6a90926f699e1c122ac

6 Likes

Okay let me break it down on how I would try to accomplish this.

STEP 1

First I would detect when the player moves using:


local RunService = game:GetService("RunService")
 
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

local function run()
    local now = tick()
    if humanoid.MoveDirection.Magnitude > 0 then -- Are we walking?
    end
end)

STEP 2

Next if we are walking I would want to tween the pet orientation up and down and side to side in whatever way you want it to look like (your on your own for this one because I’m on mobile)

STEP 3

Finally, since I’m pretty sure this would still do the tween when we jump, check that the player is grounded:

Code


local RunService = game:GetService("RunService")
 
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

local function run()
    local now = tick()
    if humanoid.MoveDirection.Magnitude > 0 and humanoid.FloorMaterial ~= nil then -- Are we walking and not jumping?
         — Animation code here
    end
end)

6 Likes

After closely examining the video I believe the way he grounds the pets is by casting a ray down and moving the pet down to where the ray first collides with something. I’ll try mixing your method and his method to see what I come up with! Cheers

4 Likes

Just an update on this: I figured it out. I am firing a ray down from the pet every frame which detects any parts/terrain cells below it. I then move the pet down to just above the point of collision using BodyMovers. https://gyazo.com/0f0ebbff30d5f4a5fa6159b00cc24e86

6 Likes

Is this done on server or client? wont there be a jittering issue? im trying something similar but havent tested for this yet

2 Likes

This is done on the client, and as far as I can see there is very little to no jittering in the pets movement. I’ll also add animations to the pets to cover up any jittering as best as I can.

1 Like

One time I was making a game, and I accidentally changed something up, and literally invented a new way of making a pet follow you. Just linear interpolate to the position you want. It works fine, unless you don’t want it to collide with anything.

1 Like

Another update here: I feel like I have perfected the movement as much as I can, completely new animations (Each pet is rigged) and all the pets follow two orderly queues behind the player.
The client also handles all functionality for all pets in the server, to ensure they are as smooth as possible.

https://gyazo.com/ad1ce626cee5bddd0576e93ba417ac7d

3 Likes

This looks great! Amazing progress. Good luck with your game!

1 Like

which body movers are you using? the way I was trying was to set the networkownership and make BodyPosition and BodyGyro on server then handle them on local using an event but It doesnt seem to work for some reason

I just manage all the players pets on each client, including their bodyposition and bodygyro. There can only be a maximum of 18 pets on a single server so it is unlikely to cause any performance issues. It also syncs pretty well with other players and I ensure that Pet deletion/unequipping/equipping is synced across all clients.

1 Like

Hey all, another update on how my system is going! I’ve definitely improved it a lot since last time I shared my progress (More than 2 months ago!), and I’m really proud of what I’ve created here.

https://gyazo.com/cb0ee0f4ee715b80ffa01db7e4999418

3 Likes

anyway way I could learn this from you(just the pet following part)? I’ll pay too coz whenever I try to use body pos and body gyro, my pets lag like hell idk why

Can you elaborate on this? This seems interesting

1 Like

Sure, take this for example:

local pet = workspace.Pet

while task.wait() do
    pet.CFrame = 
        pet.CFrame:Lerp(
             character.HumanoidRootPart.CFrame *
             CFrame.new(0, -1, -3)
        , .1)
end

Very rough sketch. It lerps to a specific position behind the humanoidrootpart.

oh… i thought it was going to be like a revolutionary thing haha.

1 Like

When I was a beginner, and I was starting to learn lerping, I realized this, and it was literally on accident!

Tell me, please, did you use the cframe to determine the position of the pet in space, or did you use only BodyMovers for that?

I only used BodyMovers, didn’t do any CFrame stuff

Is it worth to using BodyMovers now or better use constraints movers? The documentation says that the BodyMovers is deprecated.