AreaTrigger
Associated namespace: sm.areaTrigger
A userdata object representing an area trigger in the game.
Values:-
id[ int ]Get: The ID of theAreaTrigger.
| Operation | Description |
|---|---|
AreaTrigger == AreaTrigger | Checks if two instances of AreaTrigger refer to the same AreaTrigger. |
Functions
bindOnEnter
AreaTrigger:bindOnEnter( callback, object = nil )
Binds an area trigger's onEnter event to a custom callback.
The onEnter event is triggered when an object enters the trigger area.
The callback receives:
self[ table ]: The class instance.trigger[ AreaTrigger ]: The area trigger instance.results[ table ]: A table of objects that entered the trigger area.
AreaTrigger[ AreaTrigger ]: The AreaTrigger.callback[ string ]: The name of the Lua function to bind.object[ table ]: The object that will receive the callback. (optional)
MyClass = class()
function MyClass.server_onCreate( self )
local position = self.shape:getWorldPosition()
local size = sm.vec3.new( 1, 1, 1 )
self.myTrigger = sm.areaTrigger.createBox( size, position )
self.myTrigger:bindOnEnter( "onEnter" )
end
function MyClass.onEnter( self, trigger, results )
for k, object in ipairs( results ) do
print( object, "just entered" )
end
end
bindOnExit
AreaTrigger:bindOnExit( callback, object = nil )
Binds an area trigger's onExit event to a custom callback.
The onExit event is triggered when an object leaves the trigger area.
The callback receives:
self[ table ]: The class instance.trigger[ AreaTrigger ]: The area trigger instance.results[ table ]: A table of objects that left the trigger area.
AreaTrigger[ AreaTrigger ]: The AreaTrigger.callback[ string ]: The name of the Lua function to bind.object[ table ]: The object that will receive the callback. (optional)
MyClass = class()
function MyClass.server_onCreate( self )
local position = self.shape:getWorldPosition()
local size = sm.vec3.new( 1, 1, 1 )
self.myTrigger = sm.areaTrigger.createBox( size, position )
self.myTrigger:bindOnExit( "onExit" )
end
function MyClass.onExit( self, trigger, results )
for k, object in ipairs( results ) do
print( object, "just left" )
end
end
bindOnStay
AreaTrigger:bindOnStay( callback, object = nil )
Binds an area trigger's onStay event to a custom callback.
The onStay event is triggered every tick as long as an object is staying inside of the trigger area.
The callback receives:
self[ table ]: The class instance.trigger[ AreaTrigger ]: The area trigger instance.results[ table ]: A table of objects that are in the trigger area.
AreaTrigger[ AreaTrigger ]: The AreaTrigger.callback[ string ]: The name of the Lua function to bind.object[ table ]: The object that will receive the callback. (optional)
MyClass = class()
function MyClass.server_onCreate( self )
local position = self.shape:getWorldPosition()
local size = sm.vec3.new( 1, 1, 1 )
self.myTrigger = sm.areaTrigger.createBox( size, position )
self.myTrigger:bindOnStay( "onStay" )
end
function MyClass.onStay( self, trigger, results )
print( #results, "objects inside trigger area" )
end
bindOnProjectile
AreaTrigger:bindOnProjectile( callback, object = nil )
Binds an area trigger's onProjectile event to a custom callback.
The onProjectile event is triggered if a projectile collides with the trigger area.
AreaTrigger[ AreaTrigger ]: The AreaTrigger.callback[ string ]: The name of the Lua function to bind.object[ table ]: The object that will receive the callback. (optional)
getContents
AreaTrigger:getContents()
Gets the contents of the area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ table ]: The objects inside the trigger area.
getHostInteractable
AreaTrigger:getHostInteractable()
Returns the attached host interactable.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ Interactable ]: The area trigger's host interactable.
getId
AreaTrigger:getId()
Returns the id of the area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ int ]: The area trigger's id.
getShapes
AreaTrigger:getShapes()
Returns the shapes inside the trigger area.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ table ]: A table containing all Shapes that are inside the AreaTrigger, each contained in the following data structure:
getSize
AreaTrigger:getSize()
Returns the size of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ Vec3 ]: The area trigger's size.
getUserData
AreaTrigger:getUserData()
Returns the userdata set on the area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ table ]: The area trigger's userdata.
getWorldMax
AreaTrigger:getWorldMax()
Returns the world max corner position of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ Vec3 ]: The area trigger's max corner position.
getWorldMin
AreaTrigger:getWorldMin()
Returns the world min corner position of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ Vec3 ]: The area trigger's min corner position.
getWorldPosition
AreaTrigger:getWorldPosition()
Returns the world position of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ Vec3 ]: The area trigger's world position.
getWorldRotation
AreaTrigger:getWorldRotation()
Returns the world rotation of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ Quat ]: The area trigger's world rotation.
hasVoxelTerrainContact
AreaTrigger:hasVoxelTerrainContact()
Returns true if the AreaTrigger is in contact with destructable terrain.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.
- [ bool ]: Destructable terrain contact.
setShapeDetection
AreaTrigger:setShapeDetection( detectShapes )
Shape detection is off by default. When set to true the area trigger can calculate which shapes are inside of the trigger area with a call to AreaTrigger:getShapes()
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.detectShapes[ bool ]: Whether shape detection is on or off.
setSize
AreaTrigger:setSize( size )
Sets the new size of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.size[ Vec3 ]: The area trigger's new size.
setWorldPosition
AreaTrigger:setWorldPosition( position )
Sets the new world position of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.position[ Vec3 ]: The area trigger's new world position.
setWorldRotation
AreaTrigger:setWorldRotation( rotation )
Sets the new world rotation of an area trigger.
Arguments:AreaTrigger[ AreaTrigger ]: The AreaTrigger.rotation[ Quat ]: The area trigger's new world rotation.