Hello I’m working with a Pet System, and I have a problem with pet movement, the pet lag, and if I jump it bounces me away robloxapp-20230112-1824222.wmv (739,8 KB)
local RunService = game:GetService("RunService")
local Character = script.Parent.Parent
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local pet = script.Parent
local function SetPetCFrame()
pet.PrimaryPart.CFrame = HumanoidRootPart.CFrame * CFrame.new(2, 2, -3)
end -- Hroot is player's HumanoidRootPart
RunService.Heartbeat:Connect(function()
wait()
SetPetCFrame()
end)
I searched on google nothing, someone has an idea ?
Are you sure the pet has no collision? If a part’s CFrame was changed to another part CFrame (close enough for them to collide), it has a chance of flinging the other part (that’s why in my games, anything that is fast and can have contact with the player probably has no collision.
To fix the lag, you could lerp the pet position instead of positioning it, here’s an example:
local PetCFrame = pet.PrimaryPart.CFrame
local function SetPetCFrame()
PetCFrame = PetCFrame:Lerp(pet.HumanoidRootPart.CFrame * CFrame.new(2, 2, -3), 0.5)
pet.PrimaryPart.CFrame = PetCFrame
end
By the way, one thing I want to note, you don’t need to add that “wait()” in the Heartbeat function as it will barely change anything and will only make it less smooth.
local RunService = game:GetService("RunService")
local Character = script.Parent.Parent
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local pet = script.Parent
local petCFrame = HumanoidRootPart.CFrame * CFrame.new(2, 2, -3) -- create the cframe variable
local function SetPetCFrame()
petCFrame = petCFrame:Lerp(HumanoidRootPart.CFrame * CFrame.new(2, 2, -3), 0.5) -- set the cframe variable to the lerped cframe of the humanoidrootpart multiplied by 2, 2, -3
pet.PrimaryPart.CFrame = petCFrame -- set the cframe
end
RunService.Heartbeat:Connect(function(DeltaTime)
SetPetCFrame()
end)
okay I solved the problem, but the pet is a cat and I would like to make it walking, and I know how to do it, but there is a way to make the pet not anchored to the player but walking ?
okay I have tried to make something like this but the game said to me that argument3 is missed…
local RunService = game:GetService("RunService")
local Character = script.Parent.Parent
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local Body = Character:WaitForChild("Torso", 1)
local pet = script.Parent
local Humanoid = pet.Humanoid
local petCFrame = HumanoidRootPart.CFrame * CFrame.new(2, -2, 3) -- create the cframe variable
local function PetMovement()
local CurrentTime = tick()
local XDirection = math.cos(HumanoidRootPart.CFrame.X)
local YDirection = math.sin(HumanoidRootPart.CFrame.Y)
local Vector = Vector3.new(XDirection, YDirection, 0)
petCFrame = petCFrame:Lerp(Vector, 0.30)
pet.PrimaryPart.CFrame = petCFrame
end
RunService.Heartbeat:Connect(function(DeltaTime)
PetMovement()
end)
PS: sorry for all the questions but I’m new so I don’t know a lot