Roblox Item is lagging



我添加了一个网格来跟踪玩家无论他去哪里。但是当玩家运行时,网格会有点滞后。我知道它渲染不够快,但有人知道如何添加一个网格没有它滞后?

local humanoidRootPart = character:WaitForChild('HumanoidRootPart')
local backpackItemWorkspace = game.ReplicatedStorage.Meshes[pet.Name]:Clone()  
backpackItemWorkspace.Parent = game.Workspace.CurrentPets
RunService.Stepped:Connect(function()
local location = humanoidRootPart.CFrame
backpackItemWorkspace.CFrame = location * CFrame.new(2, 2, 3)
end)

使用焊缝连接网格和根部件,因此您不需要每次都使用RunService来移动网格。

local humanoidRootPart = character:WaitForChild('HumanoidRootPart')
local backpackItemWorkspace = game.ReplicatedStorage.Meshes[pet.Name]:Clone()  
backpackItemWorkspace.Parent = game.Workspace.CurrentPets
function attach(hroot, mesh)
local weld = Instance.new("WeldConstraint", mesh)
local location = hroot.CFrame
mesh.CFrame = location + Vector3.new(2, 2, 3)
weld.Part0 = hroot
weld.Part1 = mesh
return weld
end
attach(humanoidRootPart, backpackItemWorkspace)
-- please comment if it makes any errors

好的,对于那些挣扎着让宠物(网格)跟着你,总是呆在你背上的人。我已经花了几个小时研究这个问题,终于使它起作用了。你应该这样做:

local character = player.Character
local humanoidRootPart = character:WaitForChild('HumanoidRootPart')

//where you copy you pet from
local backpackItemWorkspace = game.ReplicatedStorage.Meshes[pet.Name]:Clone()
//where you keep your pets in the workspace  
backpackItemWorkspace.Parent = game.Workspace.CurrentPets
//call the function for attaching the pet
attachPet(backpackItemWorkspace, character, humanoidRootPart) 
function attachPet (pet, char, humanoidRootPart)
local focusPart = humanoidRootPart
local newPet = pet
local z = -5
local x = 1
local bodyPos = Instance.new("BodyPosition")
bodyPos.Parent = newPet
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = newPet
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
while wait() do
bodyPos.Position = focusPart.Position + focusPart.CFrame.LookVector * z + focusPart.CFrame.RightVector * x
bodyGyro.CFrame = focusPart.CFrame
end
end

当你解除宠物装备时,你必须从储存它的地方摧毁它。在我的例子中,我将它们存储在播放器上的一个文件夹中,我称之为collectionInventory。

local collectionInventory = player:WaitForChild("CollectionInventory")
collectionInventory[petName]:Destroy()

希望这可以节省其他人浪费几个小时的研究。尽管你可能会从那些"浪费的时间"中学到很多东西。;)

相关内容

  • 没有找到相关文章

最新更新