TriggerComponent

Sets the entity's collision area on an entity and provides a function to detect a collision.

# Properties

[{"index":"Vector2 BoxOffset (Deprecated) (Sync)","0":"Available on previous systems where IsLegacy is true. Sets the center point position of the collider rectangle based on the Entity."}]

[{"index":"Vector2 BoxSize (Sync)","0":"Specifies the width and height of the rectangular collider."}]

[{"index":"float CircleRadius (Sync)","0":"The radius of the circular collider. Valid when ColliderType is Circle."}]

[{"index":"string ColliderName (Deprecated) (ReadOnly) (HideFromInspector)","0":"This property is deprecated. Use CollisionGroup."}]

[{"index":"Vector2 ColliderOffset (Sync)","0":"Sets the center point position of the collider based on the Entity. Available on new systems with IsLegacy set as false."}]

[{"index":"ColliderType ColliderType (Sync)","0":"Sets the type of collider. Available on new systems with IsLegacy set as false."}]

[{"index":"CollisionGroup CollisionGroup (Sync)","0":"Set up a collision group."}]

[{"index":"boolean IsLegacy (ReadOnly)","0":"Sets whether this Component will operate with the previous system. In a new system, the Collider is affected by TransformComponent's rotation and size. You can also use a circle-shaped collider by setting the ColliderType."}]

[{"index":"boolean IsPassive (Sync)","0":"Will not perform any collision checking itself if the value is true. If TriggerComponents with true IsPassive collide, no event will occur. For an event to occur, at least one of the TriggerComponents' IsPassive must be set to false. You can improve the World performance by reducing unnecessary collision checking."}]

[{"index":"SyncList PolygonPoints (Sync)","0":"The positions of the points that make up the polygonal colliding body. Valid when ColliderType is Polygon."}]

##### 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":"void OnEnterTriggerBody(TriggerEnterEvent enterEvent) (ScriptOverridable)","0":"This function is called when entering the trigger area."}]

[{"index":"void OnLeaveTriggerBody(TriggerLeaveEvent leaveEvent) (ScriptOverridable)","0":"This function is called when exiting the trigger area."}]

[{"index":"void OnStayTriggerBody(TriggerStayEvent stayEvent) (ScriptOverridable)","0":"This function is called in every frame when entering and remaining in the trigger area."}]

##### 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."}]

# Events

[{"index":"TriggerEnterEvent","0":"This event occurts when TriggerComponent's area overlaps."}]

[{"index":"TriggerLeaveEvent","0":"This event occurs when TriggerComponent's area no longer overlaps."}]

[{"index":"TriggerStayEvent","0":"This event occurs every frame when TriggerComponent's area overlaps. Please be aware that this may negatively affect your World's function."}]

# Examples

The following is an example of creating an HP recovery space.

Increases HP while the player is inside the Entity's trigger area named Heal.  
You can use TriggerEnterEvent and TriggerLeaveEvent to know if the player is inside the trigger area.
    
    
    @Component
    script ZoneHealthRegenerator extends Component
        @Sync
        property boolean IsGettingHealed = false
        @Sync
        property number Hp = 1000
    
        @ExecSpace("ServerOnly")
        method void OnUpdate(number delta)
        if self.IsGettingHealed then
        	local player = self.Entity.PlayerComponent
    
        	self.Hp = self.Hp + (10.0 * delta)
        	player.Hp = math.floor(self.Hp)
        end
        end
    
        @ExecSpace("ServerOnly")
        @EventSender("Self")
        handler HandleTriggerEnterEvent(TriggerEnterEvent event)
        -- Parameters
        local TriggerBodyEntity = event.TriggerBodyEntity
        --------------------------------------------------------
    
        if TriggerBodyEntity.Name == "Heal" then
        	self.IsGettingHealed = true
        end
        end
    
        @ExecSpace("ServerOnly")
        @EventSender("Self")
        handler HandleTriggerLeaveEvent(TriggerLeaveEvent event)
        -- Parameters
        local TriggerBodyEntity = event.TriggerBodyEntity
        --------------------------------------------------------
    
        if TriggerBodyEntity.Name == "Heal" then
        	self.IsGettingHealed = false
        end
        end
    end
    

# SeeAlso

  * PlayerComponent
  * TriggerEnterEvent
  * TriggerLeaveEvent
  * math