AIChaseComponent

AI that allows monsters to track players. StateComponent is added automatically when it is not present.

# Properties

[{"index":"float DetectionRange","0":"Range of trace detection. If the target moves beyond that range, the trace will be paused. If the target moves back within range, it will resume the trace."}]

[{"index":"boolean IsChaseNearPlayer","0":"If the value is true, it automatically tracks the nearest player within the DetectionRange property value. If there is a target specified by the TargetEntityRef property or the SetTarget(Entity) function, it will track the specified target instead of the player."}]

[{"index":"EntityRef TargetEntityRef (ReadOnly)","0":"Designates the Entity to be tracked."}]

##### inherited from AIComponent:

[{"index":"string BehaviourTreeId (ReadOnly)","0":"The unique identifier of the behavior tree entry."}]

[{"index":"Blackboard BlackBoard (ReadOnly)","0":"This is the data store that is used in the AI behavior tree. It's managed in key-value pairs, and data is shared between behavior tree nodes."}]

[{"index":"boolean IsLegacy (ReadOnly)","0":"Sets whether to support the legacy system. Previous systems must use the ExclusiveExecutionWhenRunning property in order to set the node as Running. The legacy system is no longer supported and will be deleted at a later date."}]

[{"index":"boolean LogEnabled (ReadOnly)","0":"Outputs execution information into a log when the value is true while BehaviorTree runs. Operates in Maker mode only."}]

[{"index":"UpdateAuthorityType UpdateAuthority (ReadOnly)","0":"Update permission. Executed on the specified location (Client or Server)."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

[{"index":"Entity GetCurrentTarget()","0":"Returns the entity being tracked."}]

[{"index":"void SetTarget(Entity targetEntity)","0":"Sets it to chase targetEntity. The IsChaseNearPlayer property is automatically inactive when calling the function"}]

##### inherited from AIComponent:

[{"index":"BTNode CreateLeafNode(string nodeName, func -> BehaviourTreeStatus onBehaveFunction)","0":"Creates an Action node. Calls function that had been passed to onBehaveFunction when the node is executed. Parameter of onBehaveFunction is delta, which means time per frame."}]

[{"index":"BTNode CreateNode(string nodeType, string nodeName = nil, func -> BehaviourTreeStatus onBehaveFunction = nil)","0":"Creates an Action node based on BTNodeType. The nodeType is the type name of BTNodeType. If the onBehaveFunction isn't nil, the function that was passed to the onBehaveFunction will be called instead of functions OnInit() and OnBehave() of the BTNodeType. The parameter of the onBehaveFunction is delta, which means time per frame."}]

[{"index":"void SetRootNode(BTNode node)","0":"Sets the node as the top-level node."}]

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Examples

This is an example of a monster chasing the target that attacked it instead of blindly chasing nearby enemies. You can add and use the component written in the example code to the Chase monster.
    
    
    @Component
    script AIThreatDisplay extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
        local aiChaseComponent = self.Entity.AIChaseComponent
        if aiChaseComponent == nil then
        	return
        end
    
        aiChaseComponent.IsChaseNearPlayer = false
    
        local chatBallon = self.Entity.ChatBalloonComponent
        if chatBallon == nil then
        	chatBallon = self.Entity:AddComponent(ChatBalloonComponent)
        end
    
        chatBallon.ChatModeEnabled = false
        chatBallon.ShowDuration = 1
        chatBallon.HideDuration = 0
        chatBallon.FontSize = 1.2
        end
    
        @ExecSpace("ServerOnly")
        method void OnUpdate(number delta)
        if self.Entity.ChatBalloonComponent == nil then
        	return
        end
    
        local currentTargetEntity = self.Entity.AIChaseComponent:GetCurrentTarget()
        if currentTargetEntity == nil then
        	self.Entity.ChatBalloonComponent.AutoShowEnabled = false
        else
        	self.Entity.ChatBalloonComponent.AutoShowEnabled = true
        	self.Entity.ChatBalloonComponent.Message = "target is "..currentTargetEntity.Name
        end
        end
    
        @EventSender("Self")
        handler HandleHitEvent(HitEvent event)
        --------------- Native Event Sender Info ----------------
        -- Sender: HitComponent
        -- Space: Server, Client
        ---------------------------------------------------------
    
        -- Parameters
        local AttackCenter = event.AttackCenter
        local AttackerEntity = event.AttackerEntity
        local Damages = event.Damages
        local Extra = event.Extra
        local FeedbackAction = event.FeedbackAction
        local IsCritical = event.IsCritical
        local TotalDamage = event.TotalDamage
        ---------------------------------------------------------
        if self.Entity.AIChaseComponent == nil then
        	return
        end
    
        self.Entity.AIChaseComponent:SetTarget(AttackerEntity)
        end
    end
    

# SeeAlso

  * AIComponent
  * StateComponent