提问人:Paysmon 提问时间:11/14/2023 更新时间:11/14/2023 访问量:45
人形生物不动
The Humanoid does not move
问:
所以我在 Roblox Studio 上将这个假人焊接到 P90 模型(一把枪)上。我需要这个假人来移动,但是当我对这个假人的人形生物调用:MoveTo时,它就是不动任何帮助都值得赞赏,谢谢!
法典:
local RS = game:GetService("ReplicatedStorage")
local npcSettings = require(RS.Settings)
local npcVariables = require(RS.Variables)
local NPC = workspace:FindFirstChild("NPC Gun System")
local NPCRootPart = npcVariables.NPCRootPart
local NPCTorso = npcVariables.NPCTorso
local NPCHumanoid = npcVariables.NPCHumanoid
local Players = game:GetService("Players")
local npcProperties = {
agroDistance = 100,
fireRate = 0.1,
bulletDamage = 15,
bulletSpeed = 100,
bulletMag = 50
}
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")
local torso = char:FindFirstChild("Torso")
local humRootPart = char:FindFirstChild("HumanoidRootPart")
local function chaseTarget()
NPCHumanoid:MoveTo(humRootPart.Position)
end
local function Reload()
npcSettings.Guns.P90.Sounds.ReloadSound:Play()
--Put an animation here if you wish!
end
local function fireP90()
if hum.Health == 0 then return end
local newBullet = npcSettings.Guns.P90.BulletTrail:Clone()
newBullet.Parent = workspace
newBullet.CFrame = npcSettings.Guns.P90.Model.FirePart.CFrame * CFrame.new(0, 0, -1)
newBullet.CFrame = newBullet.CFrame * CFrame.Angles(0, math.rad(90), 0)
local Att0 = Instance.new("Attachment")
Att0.Parent = newBullet
local LinearVelocity = Instance.new("LinearVelocity")
LinearVelocity.Parent = newBullet
LinearVelocity.MaxForce = math.huge
LinearVelocity.Attachment0 = Att0
LinearVelocity.VectorVelocity = npcSettings.Guns.P90.Model.FirePart.CFrame.LookVector * npcProperties.bulletSpeed
game.Debris:AddItem(newBullet, 3)
newBullet.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
hum:TakeDamage(npcProperties.bulletDamage)
newBullet:Destroy()
end
end)
npcSettings.Guns.P90.Sounds.GunShotSound:Play()
npcVariables.isRunning = true
end
local function checkPositionAndFire()
if (NPCTorso.Position - torso.Position).Magnitude < npcProperties.agroDistance then
local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()
NPCRootPart.CFrame = CFrame.lookAt(NPCRootPart.Position, torso.Position)
end)
chaseTarget()
fireP90()
else
npcVariables.isRunning = false
end
end
if torso ~= NPCTorso then
local bulletsFired = 0
while true do
task.wait(npcProperties.fireRate)
checkPositionAndFire()
if npcVariables.isRunning == true then
bulletsFired = bulletsFired + 1
if bulletsFired >= npcProperties.bulletMag then
if npcVariables.isRunning == true then
Reload()
npcVariables.isRunning = false
end
bulletsFired = bulletsFired - bulletsFired
end
if npcSettings.Guns.P90.Sounds.ReloadSound.IsPlaying == true then
npcSettings.Guns.P90.Sounds.ReloadSound.Ended:Wait()
end
end
end
end
end)
相关代码:
local function chaseTarget()
NPCHumanoid:MoveTo(humRootPart.Position)
end
local function checkPositionAndFire()
if (NPCTorso.Position - torso.Position).Magnitude < npcProperties.agroDistance then
local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()
NPCRootPart.CFrame = CFrame.lookAt(NPCRootPart.Position, torso.Position)
end)
chaseTarget()
fireP90()
else
npcVariables.isRunning = false
end
end
我已经尝试调用另一种方法并更改其 CFrame 以使假人移动,正如我所说,我希望使假人的人形移动。
答: 暂无答案
评论