sm.areaTrigger
Associated object type: AreaTrigger
An area trigger 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 that are in a room.
Functions
createAttachedBox
sm.areaTrigger.createAttachedBox( interactable, dimension, position, rotation, filter, userdata )
Creates a new area trigger box with a given size that stays attached to an Interactable.
If a filter is specified, the trigger area will only be able to detects objects of that certain type.
See sm.areaTrigger.filter for more information about filters.
Creating an area trigger with zero in any of the 3 dimension
values (x, y, z) will cause a game crash!
interactable
[ Interactable ]: The host interactable.dimension
[ Vec3 ]: The trigger size.position
[ Vec3 ]: The position offset (defaults to none).rotation
[ Quat ]: The rotation offset (defaults to none)filter
[ int ]: The filter. Defaults to no filter.userdata
[ table ]: A table of data that can be retrieved usingareaTrigger:getUserData()
.
- [ AreaTrigger ]: The created areaTrigger.
MyShape = class()
function MyShape.server_onCreate( self )
local position = self.shape:getWorldPosition()
local size = sm.vec3.new( 1, 1, 1 )
self.myTrigger = sm.areaTrigger.createAttachedBox( self.interactable, size )
end
MyShape = class()
function MyShape.server_onCreate( self )
local position = self.shape:getWorldPosition()
local size = sm.vec3.new( 1, 1, 1 )
--Only detect characters
local filter = sm.areaTrigger.filter.character
self.myTrigger = sm.areaTrigger.createAttachedBox( self.interactable, size, _, _, filter )
end
createAttachedSphere
sm.areaTrigger.createAttachedSphere( interactable, radius, position, rotation, filter, userdata )
Creates a new area trigger sphere with a given size that stays attached to an Interactable.
If a filter is specified, the trigger area will only be able to detects objects of that certain type.
See sm.areaTrigger.filter for more information about filters.
Arguments:interactable
[ Interactable ]: The host interactable.radius
[ number ]: The trigger radius.position
[ Vec3 ]: The position offset (defaults to none).rotation
[ Quat ]: The rotation offset (defaults to none)filter
[ int ]: The filter. Defaults to no filter.userdata
[ table ]: A table of data that can be retrieved usingareaTrigger:getUserData()
.
- [ AreaTrigger ]: The created areaTrigger.
createBox
sm.areaTrigger.createBox( size, position, rotation, filter, userdata )
Creates a new area trigger box.
If a filter is specified, the trigger area will only be able to detects objects of that certain type.
See sm.areaTrigger.filter for more information about filters.
Creating an area trigger with zero in any of the 3 size
values (x, y, z) will cause a game crash!
size
[ Vec3 ]: The trigger size.position
[ Vec3 ]: The position.rotation
[ Quat ]: The rotation (defaults tosm.quat.identity
).filter
[ int ]: The filter. Defaults to no filter.userdata
[ table ]: A table of data that can be retrieved usingareaTrigger:getUserData()
.
- [ AreaTrigger ]: The created areaTrigger.
createBoxWater
sm.areaTrigger.createBoxWater( size, position, rotation, filter, userdata )
Creates a new area trigger box that represents water, ie. certain objects can't be placed in it.
If a filter is specified, the trigger area will only be able to detects objects of that certain type.
See sm.areaTrigger.filter for more information about filters.
Creating an area trigger with zero in any of the 3 size
values (x, y, z) will cause a game crash!
size
[ Vec3 ]: The trigger size.position
[ Vec3 ]: The position.rotation
[ Quat ]: The rotation (defaults tosm.quat.identity
).filter
[ int ]: The filter. Defaults to no filter.userdata
[ table ]: A table of data that can be retrieved usingareaTrigger:getUserData()
.
- [ AreaTrigger ]: The created areaTrigger.
createSphere
sm.areaTrigger.createSphere( radius, position, rotation, filter, userdata )
Creates a new area trigger sphere.
If a filter is specified, the trigger area will only be able to detects objects of that certain type.
See sm.areaTrigger.filter for more information about filters.
Arguments:radius
[ number ]: The trigger radius.position
[ Vec3 ]: The position.rotation
[ Quat ]: The rotation (defaults tosm.quat.identity
).filter
[ int ]: The filter. Defaults to no filter.userdata
[ table ]: A table of data that can be retrieved usingareaTrigger:getUserData()
.
- [ AreaTrigger ]: The created areaTrigger.
destroy
sm.areaTrigger.destroy( trigger )
Destroys an areaTrigger.
Arguments:trigger
[ AreaTrigger ]: The trigger to destroy.