# sm.areaTrigger

An <strong>area trigger</strong> is an invisible collider in the world that can trigger events when objects move in or out of it. This allows the script to, for instance, detect when a character enters a door, or count the number of shapes there are in a room.

**Kind:** API page

**Environments:** Game

## Game

[Open the full Game reference](../Game-Script-Environment/Static-Functions/sm.areaTrigger.md)

Example usage:

```lua
function MyClass.server_onCreate( self )
	local size = sm.vec3.new( 1, 1, 1 )
	local position = self.shape:getWorldPosition()

	self.myArea = sm.areaTrigger.createBox( size, position )
	self.myArea:bindOnEnter( "onEnter" )
end

function MyClass.onEnter( self, trigger, results )
	for i, object in ipairs( results ) do
		print( object, "just entered" )
	end
end
```

Example with a filter:

```lua
function MyClass.server_onCreate( self )
	local size = sm.vec3.new( 10, 10, 5 )
	local position = sm.vec3.new( 50, 40, 30 )

	-- Only detect characters
	local filter = sm.areaTrigger.filter.character

	self.myArea = sm.areaTrigger.createBox( size, position, filter )
	self.myArea:bindOnStay( "onStay" )
end

-- Callback receives a list of characters
function MyClass.onStay( self, trigger, results )
	if #results > 0 then
		print( "Intruder alert!" )
	end
end
```
