You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A really good pathfinding AI for enemies
What is the issue? Include screenshots / videos if possible!
The ai makes the rig rotate strangely, no other problems
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Nope
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local hrt=script.Parent.HumanoidRootPart
local hum=script.Parent.Humanoid
local pfs=game:GetService("PathfindingService")
local anim=hum:LoadAnimation(script.attack)
db=false
local function FindTarget()
local target
local distance
local maxdistance=600
for i,v in pairs(game.Players:GetPlayers()) do
if v.Character then
local hrp=v.Character:FindFirstChild("HumanoidRootPart")
local distance=(hrt.Position-hrp.Position).magnitude
if distance<maxdistance then
target=hrp
maxdistance=distance
end
if distance<5 then
if db==false then
anim:Play()
target.Parent.Humanoid.Health=0
db=true
wait(game.Players.RespawnTime)
db=false
end
end
end
end
return target
end
local path=pfs:CreatePath({
AgentCanJump=true,
AgentCanClimb=true
})
local function follow(target)
path:ComputeAsync(hrt.Position, target.Position)
local wp=path:GetWaypoints()
for i,v in wp do
hum:MoveTo(v.Position)
task.wait()
end
end
while task.wait() do
local target=FindTarget()
if target then
follow(target)
end
end
local function follow(target)
path:ComputeAsync(hrt.Position, target.Position)
local wp=path:GetWaypoints()
for i,v in wp do
hum:MoveTo(v.Position)
hum.MoveToFinished:Wait()
end
end