【发布时间】:2021-02-10 00:27:43
【问题描述】:
我使用 MoveTo 来跟踪位置并更改 CFrame 以进行旋转,但它看起来非常锯齿。我认为问题在于代码在服务器端而不是在客户端,因为我希望其他玩家能够看到玩家后面的对象
【问题讨论】:
标签: roblox
我使用 MoveTo 来跟踪位置并更改 CFrame 以进行旋转,但它看起来非常锯齿。我认为问题在于代码在服务器端而不是在客户端,因为我希望其他玩家能够看到玩家后面的对象
【问题讨论】:
标签: roblox
尝试使用weldConstrain。您可以通过代码创建它并将 2 个部分连接到它。这些零件将彼此保持相同的相对位置。以下是有关该主题的 API 参考链接:https://developer.roblox.com/en-us/api-reference/class/WeldConstraint 下面是一个示例代码,当玩家加入游戏时,它会在玩家的头顶添加一个部分:
local Players = game:GetService('Players') -- get's the players service
local function OnPlayerAdded(player)
local PlayerCharacter = player.Character
-- waits until the player's character loads
while PlayerCharacter == nil do
wait(1)
PlayerCharacter = player.Character
end
-- Get's the player's model in workspace
local PlayerModel = workspace:WaitForChild(PlayerCharacter.Name)
-- Get's the player's head inside it's model
local PlayerHead = PlayerModel:WaitForChild('Head')
-- Write the path to the part you want to follow the player, bellow
local FollowPartOriginal = workspace:WaitForChild('Part')
-- If you want to clone the part, so more players can be followed by it,
-- don't delete the line below, if you want only 1 part, delete the line below.
local FollowPart = FollowPartOriginal:Clone()
-- set's the part position on top of the player's head, with an offset
FollowPart.Position = PlayerHead.CFrame.p + Vector3.new(0,2,0)
FollowPart.Parent = workspace
-- creates a weldconstrain
local WeldConstraint = Instance.new('WeldConstraint')
-- connect's the weld to the player's head and the other part
WeldConstraint.Part0 = PlayerHead
WeldConstraint.Part1 = FollowPart
WeldConstraint.Parent = PlayerHead
end
Players.PlayerAdded:Connect(OnPlayerAdded)
将此代码放在脚本中(不是本地脚本)。 如果单独使用函数,别忘了放 player 参数。该参数需要包含玩家实例(例如:game.Players.PlayerName) 要更改零件位置,请使用此代码行中的偏移量:
FollowPart.Position = PlayerHead.CFrame.p + Vector3.new(write offset here)
如果您希望零件停止跟随玩家,请编写脚本来删除零件或焊接约束(玩家头部的孩子)
【讨论】: