对于篮球比赛中的NPC,哪种算法最合适?

时间:2019-06-22 08:13:09

标签: lua roblox

现在我目前正在尝试国际象棋常用的alpha beta修剪算法,可以将法院分解为网格系统,但这只是处于理论状态。因此,如果您对篮球的防守和进攻Ai有任何建议,将不胜感激。我已经尝试寻找有助于在2k和NBA Live之类的著名篮球比赛中运行npc的代码,但ive变干了,病了,我现在能得到什么。

现在,NPC只是根据我自己做的比赛设定的位置,但是防守NPC使用寻路来达到进攻对手和球门之间的位置是相当低效和可预测的

local RunService = game:GetService("RunService")
local HB = RunService.Heartbeat

local module = {}

module.PathFind = function(OppositeTeam ,Team, ActualPlayer)
    while script.Parent.Configuration.Possesion.Value == false do
    local PathfindingService = game:GetService("PathfindingService")
    local Humanoids = {}
    local Parents = {}
    local Defense = {}
    for OtherTeam, Player in pairs(OppositeTeam) do
        if Player:IsA"Humanoid" then
            if Player.Parent ~= "1" then
                table.insert(Defense, Player.Parent.HumanoidRootPart)
            end
        end
    end
    for TheTeam, Player in pairs(Team) do
        if Player:IsA"Humanoid" then
            if Player.Parent.Name ~= ActualPlayer then
                print(ActualPlayer)
                table.insert(Humanoids, Player)
                table.insert(Parents, Player.Parent)
            end
        end
    end
    local Path = PathfindingService:CreatePath()
    for  OT = 1, #Humanoids do
        local Character = Defense[OT]
        local Goal = Character.Position + (script.Parent.Configuration.Goal.Value.Position - Character.Position).Unit * 5
            Path:ComputeAsync(Parents[OT].HumanoidRootPart.Position, Goal)      
            local points = Path:GetWaypoints()
        if Path.Status == Enum.PathStatus.Success then
            for i, marker in pairs(points) do
            Humanoids[OT]:MoveTo(marker.Position)
                if marker.Action == Enum.PathWaypointAction.Jump then
                    Humanoids[OT].Jump = true
                end
            end
        end
    end
    HB:Wait()
    end
end

0 个答案:

没有答案