Hello!
I am having this issue that I am unable to solve, and am stuck on. I am not sure where the issue is inside the script, but I am pretty sure it’s not the raycast but I am not sure. The Script and an Example video on what I mean are down below, if you need anymore information I will gladly give it!
Video of what I mean:
(Used psx pets as example)
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 library.LocalPlayer.Character.PrimaryPart.Position.Y
end
end
local function positionPets(character, folder)
for i, pet in pairs(folder:GetChildren()) do
local radius = 5
local angle = i + (circle / #folder:GetChildren())
local x, z = getPosition(angle, radius)
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(library.LocalPlayer.Character.PrimaryPart.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
library.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)
Thanks! Any help will be very much appreciated.