Pet following system issue

This is what I mean, the pet is bobbing but it’s tilting to the right.

I don’t think CFrame:Lerp() returns orientation in Z, Y, X order so maybe switch “x” with “z” in the last line where you set the pet’s CFrame.

1 Like

It’s definitely in order. The Z axis is moving like the pet’s Z axis.

Maybe it’s your model’s orientation messing with the angle then, is it set to 0 out of playsolo?

Hey, I’m not sure what you mean. Do you want the pet to circle you?

No, I just want the pet to look in the player’s direction when walking and look at the character when the player is not walking. Sorry for the late reply.

Hi Legendary it seems you are having trouble with making pets look at you! I recommend Body Movers!

 game:GetService("RunService").RenderStepped:Connect(function()
        local PetTable = workspace.Pets:WaitForChild(plr.Name):GetChildren()
        local PetOffset = CFrame.new(0,1 * math.sin(tick() * 4),14)

        for i, v in pairs(workspace.Pets:WaitForChild(plr.Name):GetChildren()) do
            local Offset = 0.5
            local PetHolder = workspace.Pets:WaitForChild(plr.Name):GetChildren()
            local Angle = ((i + Offset) / #PetHolder) * math.pi * 2
            v.PrimaryPart.BodyPosition.Position = (HumanoidRootPart.CFrame * CFrame.Angles(0,Angle,0) * PetOffset).p
            
            v.PrimaryPart.BodyGyro.CFrame = CFrame.new(v.PrimaryPart.Position, HumanoidRootPart.Position)
            
        end
    end)

Using math.sin we can make such an animation. Very sorry if its not exactly similar. If you are interested in this method I can send you my body gyro and body position Properties too!

LOL I AM VERY SORRY FOR USING A BGS ASSET. I just wanted to see how it looks if big.

Yes, that work perfectly but the pet rotation is still not solved though. I could easily get the Y angle axis from the CFrame.new(pos, lookat) to make it look at the player but that will only make the rotation even worse when I add in the bobbing movement.

Wait, I realised there is a function called cf:ToObjectSpace(). Sorry for the inconvenience. :sweat_smile:

If you still need help, you can just do something like

local LookAt = CFrame.new(Pet.Position, RootPart.Position + RootPart.Velocity * 10)

I have been experiencing body movers bug or something. First, the pets start teleporting around and then it finally returns back to normal. I don’t know if I did anything wrong.


Also as you can see in the video some pets aren’t looking the right way. Here is my script.

local plr = game.Players.LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()

local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local fullCircle = 2 * math.pi

local function getXAndZPositions(angle)
	local x = math.cos(angle) * 10
	local z = math.sin(angle) * 10
	return x, z
end

game:GetService("RunService").RenderStepped:Connect(function()
	local PetTable = workspace.Pets:WaitForChild(plr.Name):GetChildren()
	local cos = math.cos(6 * time() + 1.6)/3
	local sin = math.sin(6 * time() + 1.6)/3

	for i, v in pairs(PetTable) do
		local _, RotY, _ = CFrame.new(v.PrimaryPart.Position, HumanoidRootPart.Position):ToEulerAnglesXYZ()
		
		local x, z = getXAndZPositions(i * (fullCircle / #PetTable))
		
		v.PrimaryPart.BodyPosition.Position = HumanoidRootPart.Position + Vector3.new(x, sin, z)

		v.PrimaryPart.BodyGyro.CFrame = CFrame.Angles(0,RotY,0) * CFrame.fromEulerAnglesXYZ(cos, 0, 0)

	end
end)

It seems you have multiple code in the background playing. Delete all Lerp related code. ALSO you must play with Body Position and Body Gyro a bit more. They are pretty tough concepts


v.PrimaryPart.BodyGyro.CFrame = CFrame.Angles(0,RotY,0) * CFrame.fromEulerAnglesXYZ(cos, 0, 0)

v.PrimaryPart.BodyGyro.CFrame = HumanoidRootPart.CFrame

Do not use BodyGyro for math. Do all math in Body Position.

1 Like

Though, there aren’t any lerps that is interfering with these pets.

Did you make this pet, or is it from something else, because there could be something embedded in there.

I didn’t make this pet, my friend of mine made a few pets for this simulator.

Ok then you should ask him about it or check every nook and cranny for something that could be in there…

He said he used meshparts and special meshes. Nothing else.

Are there any scripts of any kind, or anything else that isn’t a part or mesh in the pet that you didn’t put in there?

Nope, It’s all meshparts and special meshes. Nothing else :man_shrugging:

Finally, I have figured out the issue. I realized that I was adding angle value to the original cframe angle, not setting it. Also, I totally didn’t realize CFrame.fromEulerAnglesXYZ() existed at all. Here is the solution for those of you who have the same problem or want to make a similar pet movement.

local plr = game.Players.LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()

local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local fullCircle = 2 * math.pi

local function getXAndZPositions(angle)
	local x = math.cos(angle) * 10
	local z = math.sin(angle) * 10
	return x, z
end

local function getAngle(touch, center)
	return math.atan2(touch.X - center.X, touch.Z - center.Z)
end

game:GetService("RunService").RenderStepped:Connect(function()
	local PetTable = workspace.Pets:WaitForChild(plr.Name):GetChildren()
	local cos = math.cos(5 * time() + 1)/4
	local sin = math.sin(5 * time() + 1.6)/2

	for i, v in pairs(PetTable) do

		local yAngle = Character.Humanoid.MoveDirection.Magnitude > 0 and -- this will see if the player is moving or not
			getAngle(v.PrimaryPart.Position, v.PrimaryPart.Position + HumanoidRootPart.CFrame.LookVector) or --Changes yAngle to where the player is looking
			getAngle(v.PrimaryPart.Position, HumanoidRootPart.Position) --Makes the pet look at the player

		local x, z = getXAndZPositions(i * (fullCircle / #PetTable)) -- Equally splits the pets in a circle around the player

		v.PrimaryPart.CFrame = v.PrimaryPart.CFrame:Lerp(CFrame.new(HumanoidRootPart.CFrame.p) --I removed the original angle because the pet would break due to adding angle value to this cframe
			* CFrame.Angles(0, yAngle,0) -- Turns the pet around
			* CFrame.fromEulerAnglesXYZ(cos, 0, 0) --Rotate pet on the X axis in a local space
			+ Vector3.new(x, sin, z), -- Places the pet in an equally split circle around the player and moves pet up and down
			0.1
		)

	end
end)


Special thanks to @heII_ish and @FelixProfit and those of you that helped me as well. Thank you so much <33

4 Likes