敌人的敌人
我有 npc ,大概是敌人。我希望它能返回 原始问题 和 原始方向 在玩家死亡。 但是(如在代码计算中所标记的),具有函数 :moveto() ,该字符不会返回到实际的相同位置,而是近似位置。例如:
print(npc.humanoidRootpart.position) - 输出:x:11.5,y:-2.13,z:15.49 打印(原始位置) - 输出:x:11.4923973,y:-2.13432,z:15.49
这是我的代码:
local FollowZone = script.Parent
local NPC = FollowZone.Parent
local OriginalOrientation = NPC.HumanoidRootPart.Orientation
local OriginalPosition = NPC.HumanoidRootPart.Position
print(OriginalPosition)
local Fighting = 2 -- 1; No Fighting. 2; Neutral. 3; Fighting
local function OnTouch(Part)
if Part.Parent:FindFirstChild("Humanoid") ~= nil and tostring(Part.Parent.Parent.Name) ~= "Enemies" then
local Target = game:GetService("Workspace"):WaitForChild(Part.Parent.Name)
Fighting = 3
while Fighting == 3 do
NPC.Humanoid:MoveTo(Target.HumanoidRootPart.Position)
if Target.Humanoid.Health == 0 then
Fighting = 1
BackToPosition()
BackToOrientation()
end
wait()
end
end
end
function BackToPosition()
while Fighting == 1 do
NPC.Humanoid:MoveTo(OriginalPosition)
print(NPC.HumanoidRootPart.Position) -- X: 11.5, Y: -2.13, Z: 15.49
print(OriginalPosition) -- X: 11.4923973, Y: -2.13432, Z: 15.49
if NPC.HumanoidRootPart.Position == OriginalPosition then
Fighting = 2
end
wait()
end
end
function BackToOrientation()
while NPC.HumanoidRootPart.Orientation ~= OriginalOrientation do
for Index = 1, OriginalOrientation.X do
NPC.HumanoidRootPart.Orientation = Vector3.new(Index, OriginalOrientation.Y, OriginalOrientation.Z)
end
wait()
end
end
script.Parent.Touched:Connect(OnTouch)
I have NPC which, presumably, is an Enemy. I want it to return to OriginalPosition and OriginalOrientation after the player dies.
However (as marked in a code-comment), with function :MoveTo(), the character doesn't return to the actual same position but an approximate. By example:
print(NPC.HumanoidRootPart.Position) -- Output: X: 11.5, Y: -2.13, Z: 15.49 print(OriginalPosition) -- Output: X: 11.4923973, Y: -2.13432, Z: 15.49
This is my code:
local FollowZone = script.Parent
local NPC = FollowZone.Parent
local OriginalOrientation = NPC.HumanoidRootPart.Orientation
local OriginalPosition = NPC.HumanoidRootPart.Position
print(OriginalPosition)
local Fighting = 2 -- 1; No Fighting. 2; Neutral. 3; Fighting
local function OnTouch(Part)
if Part.Parent:FindFirstChild("Humanoid") ~= nil and tostring(Part.Parent.Parent.Name) ~= "Enemies" then
local Target = game:GetService("Workspace"):WaitForChild(Part.Parent.Name)
Fighting = 3
while Fighting == 3 do
NPC.Humanoid:MoveTo(Target.HumanoidRootPart.Position)
if Target.Humanoid.Health == 0 then
Fighting = 1
BackToPosition()
BackToOrientation()
end
wait()
end
end
end
function BackToPosition()
while Fighting == 1 do
NPC.Humanoid:MoveTo(OriginalPosition)
print(NPC.HumanoidRootPart.Position) -- X: 11.5, Y: -2.13, Z: 15.49
print(OriginalPosition) -- X: 11.4923973, Y: -2.13432, Z: 15.49
if NPC.HumanoidRootPart.Position == OriginalPosition then
Fighting = 2
end
wait()
end
end
function BackToOrientation()
while NPC.HumanoidRootPart.Orientation ~= OriginalOrientation do
for Index = 1, OriginalOrientation.X do
NPC.HumanoidRootPart.Orientation = Vector3.new(Index, OriginalOrientation.Y, OriginalOrientation.Z)
end
wait()
end
end
script.Parent.Touched:Connect(OnTouch)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)