Set the AI moving target point||doc135562

September 20, 2022

Format

 Entity:setAITargetPos(pos, enable) 
  • The class to which the function belongs:Entity

Description

Set the AI target point, if it takes effect immediately, the AI will move to the target point immediately.


Parameters

Parameters type Description
pos Vector3 target location
enable bool Effective immediately

Code Samples

On the server side of the entity templateObject scriptWhen the entity is injured, register aCallback function, If enemy exists, turn on AI and set AI target point

Trigger.addHandler(this:cfg(), "ENTITY_DAMAGE", function(context)
    local entity = context.obj1
    local from = context.obj2
    if from then
        entity:startAI()
        local control = entity:getAIControl()
        control:setAiData("homeSize", 50)
        control:setAiData("enableNavigate", true)
        entity:setAITargetPos(from:getPosition(),true)
    end
end)