Pet jumps when character jumps

Hello! I am having an issue, where when the Character jumps, the pets also jump, but I want it to stay on the ground. I am using ray cast, but the issue is, is that it’s also following the character’s Y, so it’ll do things like this.
(Using pet simulator x pets as testing)
When I’m on a part or something like that:



When I’m on the ground:

This is the script:

local runService = game:GetService("RunService")
local playerPets = workspace:WaitForChild("Player_Pets")
local circle = math.pi * 2
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
wait(2)
local function getPosition(angle, radius)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end
local Paramas = RaycastParams.new()
Paramas.FilterDescendantsInstances = {game.Workspace.Player_Pets:GetDescendants(), game.Workspace.Annexsohn}
Paramas.FilterType = Enum.RaycastFilterType.Blacklist
Paramas.IgnoreWater = true;
function GetY(pos)
	if workspace:Raycast(pos + Vector3.new(0,15,0),Vector3.new(0,-100,0),Paramas) then
		return workspace:Raycast(pos + Vector3.new(0,15,0),Vector3.new(0,-100,0),Paramas).Position.Y - 3.15
	--else
	--	return character.PrimaryPart.Position.Y
	end
end
local function positionPets(character, folder)
	for i, pet in pairs(folder:GetChildren()) do
		--		local radius = 2+#folder:GetChildren()
		local radius = 5
		local angle = i + (circle / #folder:GetChildren())
		local x, z = getPosition(angle, radius)
		local _, characterSize = character:GetBoundingBox()
		--		local _, petSize = pet:GetBoundingBox()

		local offsetY = -  character.LowerTorso.Position.Y
		local sin = (math.sin(15 * time() + 1.6)/.5)+1
		local cos = math.cos(7 * time() + 1)/4

		local petData = require(game.ReplicatedStorage:FindFirstChild("PetModels"):FindFirstChild(pet.Name):FindFirstChild("petData"))

		if character.Humanoid.MoveDirection.Magnitude > 0 then
			if petData["flys"] == false then
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(pet.Position)+sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1)
			else
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(pet.Position)/2+math.sin(time()*3)+1, z),0.1)
			end 
		else
			if petData["flys"] == false then 
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(pet.Position), z) ,0.1)
			else
				pet.CFrame = pet.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, GetY(pet.Position)/2+math.sin(time()*3)+1, z) ,0.1)
			end
		end
	end
end
runService.RenderStepped:Connect(function()
	for _, PlrFolder in pairs(playerPets:GetChildren()) do
		local Player = game.Players:FindFirstChild(PlrFolder.Name) or nil
		if Player ~= nil then
			local character = Player.Character or nil
			if character ~= nil then
				positionPets(character, PlrFolder)
			end
		end
	end
end)

Any help will be appreciated! :smile:

1 Like

Any help will be very much appreciated! :smile:

If anyone knows, it’ll be very greatly appreciated!

Do you know if the raycast is hitting the player?

CFrame.new(x, GetY(pet.Position)+sin, z)

Well, you are adding sin to the Y axis, thus they increase height in a circular pattern
image

If you look, it’s inside the table to ignore it. Just made it mine just for easy testing, and if it did, it’ll just be sitting on my head.

Without sin, it doesn’t have a good animation as shown right here:


With sin:

Do you have any ideas on what could solve my issue? Cause clearly, it isn’t that.

If anyone knows, it’ll be greatly appreciated!

Not sure if you’re willing to share the place as a download, but if you could that would be helpful.

Of course! Also, sorry for the late reply. The notification didn’t show up until now.
game.rbxl (43.9 KB)

When clicking X and B I seemed to have errors,
image

Just add a folder in Player_Pets with your name.

or use this file instead.
game.rbxl (44.0 KB)

I’m sorry, but I have been trying to fix your issue but I am also stuck.

Hey i think i got it to work, if this is what you wanted.
image

2 Likes

Hey! What’d you do? I would love to see! Although, I was able to fix it with some others help!

I don’t know if you still need help since this was a while ago, but as you said its following in the y vector too, so instead of lerping it to ass the axises of the characters primarypart, you would do something like this:
(character.PrimaryPart.CFrame - Vector3.new(0,character.PrimaryPart.Position.Y,0)

Hi, what did you do to achieve this I been looking for something like this for a very long time.

i fixed it for you
Screenshot_1
source: game.rbxl (42,6,KB)