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!