Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

AI - Path Finding System?

Asked by 6 years ago

Is it possible use the path finding service and make it so when a player shoots at the NPC the NPC will get to the closest piece of cover it can find and hide behind it and wait until it has a chance to shoot back? I've been searching for this answer for ages and my last conclusion was scripting helpers.

An Example:

Lets say, your doing a mission going down a "Space Ship" and you spot an enemy and they spot you to, the first thing I want to make that enemy do is get to cover and find the right times to shoot back at that player.

0
I'm fairly new to the Path Finding System, I'm originally a C# programmer that has moved to Lua. I'm still trying to work out things with Lua, its fairly different and I sometimes import c# mechanics in Lua and its quite annoying.Like namespace and crap (I will seen learn to stop that). xXiNotoriousXx 31 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

I'm not aware of anything related to the PFS which will do this for you.

I would recommend just activating a .Changed event on the AI's humanoid to see when they are shot at or hurt and then search for the closest area of cover. You can do this by naming all parts in Workspace that can be used as cover something specific and then simply use magnitude to find out which one is the closest and navigate to it using PFS. Here's an example.

function findCover()
    local ClosestDistance = 10000000
    local ClosestObject
    for _,a in pairs(workspace:GetChildren()) do
        if (a.Name == 'Cover') then
            local dis = (robot.Torso.Position - a.Position).magnitude
            if (dis < ClosestDistance) then
                ClosestObject = a
                ClosestDistance = dis
            end
        end
    end
    return ClosestObject
end

robot.Humanoid.Changed:Connect(function(prop)
    if (prop == 'Health') then
        local cover = findCover()
        -- get to the chopper!!
    end
end)

Of course, you'll need to include a check to determine when combat is over or the threat is gone and then proceed as normally.

0
Ah... Interesting, so basically this script just makes it so the npc walks to the object thats near it (Hard to explain) I could set up an animation so it will crouch as well as a remove event to the player shooting in a certain radius of the npc. I'm fairly new to RLua (Im above average in Lua I would say) and this proberly out of my knowledge but 'Give it a try' FAIL - First Attempt in learning. xXiNotoriousXx 31 — 6y
0
Pretty much, yeah. You said you're familiar with other languages so you'll probably get the hang of it fairly quickly. TheBenSquare 47 — 6y
Ad

Answer this question