I would like to have the same effect in my Roblox game, when you walk your pets look at where you are facing and when you’re idle your pets are looking you.
I think I have to use HumanoidStates.
But it is not the problem to detect when the player is idle or when the player run.
I think they user AlignPositions and AlignOrientations for their pets.
So the problem I have is to know how to turn the pets to the player when he is Idle.
You can check if the player’s character’s humanoid’s StateType using Humanoid:GetState(), if the humanoid state is Idle then make the pets look towards the player, if not, make them face the same direction as the player’s humanoid root part. Read more about HumanoidStateType here.
If you’re using alignorientation and alignposition, you could have one attachment parented to a part in the pet (that part’s lookvector should point to where the pet is facing). The other attachment could be parented to terrain. Then, every frame, change the cframe of the attachment that is parented to terrain. You’ll need to add some things to this yourself, but maybe it’ll help.
local RunService = game:GetService("RunService")
local petPart = -- the part that will have an attachment
local characterPart = -- maybe head?
local hrp = -- humanoidrootpart
local alignPos = -- the alignPosition
local alignOri = -- the alignOrientation
local attach0, attach1 = Instance.new("Attachment"), Instance.new("Attachment")
alignPos.Attachment0, alignPos.Attachment1 = attach0, attach1
attach0.Parent, attach1.Parent = petPart, workspace.Terrain
alignPos.Parent, alignOri.Parent = petPart, petPart
local function update()
local pos = -- the position where the pet should go to
local dir
if --[[idle check]] then
dir = characterPart.Position-petPart.Position
else dir = hrp.LookVector
end
attach1.CFrame = CFrame.LookAt(pos, pos+dir)
end
RunService.Heartbeat:Connect(update)