Unit
Associated namespace: sm.unit
A userdata object representing a unit in the game.
Operations:Operation | Description |
---|---|
Unit == Unit | Checks if two instances of Unit refer to the same Unit . |
-
character
[ Character ]Get
: (Server-Only) The unit's character.
-
eyeHeight
[ number ]Set
: (Server-Only) Sets the unit's eye height.
-
id
[ int ]Get
: (Server-Only) The unit's id.
-
publicData
[ table ]Get
: (Server-Only) The unit's server public data.Set
: (Server-Only) Sets the unit's server public data.
-
visionFrustum
[ table ]Set
: (Server-Only) Sets the unit's vision frustum.
self.unit.visionFrustum = {
{ 3.0, math.rad( 80.0 ), math.rad( 80.0 ) },
{ 20.0, math.rad( 40.0 ), math.rad( 35.0 ) },
{ 40.0, math.rad( 20.0 ), math.rad( 20.0 ) }
}
Functions
createState
unit:createState( name )
Server-Only
Creates an AI state from a name (See AiState).
Arguments:unit
[ Unit ]: The unit.name
[ string ]: The name of the state.
- [ AiState ]: The created AI state.
destroy
unit:destroy()
Server-Only
Destroys the unit.
Arguments:unit
[ Unit ]: The unit.
getCharacter
unit:getCharacter()
Server-Only
Returns the unit's character.
Arguments:unit
[ Unit ]: The unit.
- [ Character ]: The unit's character.
getCurrentFacingDirection
unit:getCurrentFacingDirection()
Server-Only
Returns the unit's current facing direction.
Arguments:unit
[ Unit ]: The unit.
- [ Vec3 ]: The unit's facing direction.
getCurrentMovementDirection
unit:getCurrentMovementDirection()
Server-Only
Returns the unit's current movement direction.
Arguments:unit
[ Unit ]: The unit.
- [ Vec3 ]: The unit's movement direction.
getId
unit:getId()
Server-Only
Returns the unit's id.
Arguments:unit
[ Unit ]: The unit.
- [ int ]: The unit's id.
getPublicData
unit:getPublicData()
Server-Only
Returns the unit's server public data.
Arguments:unit
[ Unit ]: The unit.
- [ table ]: The unit's server public data.
sendCharacterEvent
unit:sendCharacterEvent( event )
Server-Only
Sends an event to the unit's character script.
The event is received by the client_onEvent callback in the character script.
Arguments:unit
[ Unit ]: The unit.event
[ string ]: The event.
setFacingDirection
unit:setFacingDirection( dir )
Server-Only
Sets the unit's facing direction.
Arguments:setHearingData
unit:setHearingData( noiseScale )
Server-Only
Notifies the unit that it heard a sound.
Arguments:unit
[ Unit ]: The unit.noiseScale
[ number ]: The noise amount.
setMovementDirection
unit:setMovementDirection( dir )
Server-Only
Sets the unit's movement direction.
Arguments:setMovementType
unit:setMovementType( type )
Server-Only
Sets the unit's movement type.
Valid types are "stand", "walk", "sprint" and "crouch"
Arguments:unit
[ Unit ]: The unit.type
[ string ]: The movement type.
setPublicData
unit:setPublicData( data )
Server-Only
Sets the unit's server public data.
Arguments:unit
[ Unit ]: The unit.data
[ table ]: The data to set.
setWantsJump
unit:setWantsJump( state )
Server-Only
Sets the unit to jump.
Arguments:unit
[ Unit ]: The unit.state
[ bool ]: Whether the unit should jump or not.
setWhiskerData
unit:setWhiskerData( whiskerCount, maxAngle, startLength, endLength )
Server-Only
Sets the whisker data for obstacle avoidance.
Arguments:unit
[ Unit ]: The unit.whiskerCount
[ int ]: The whisker count.maxAngle
[ number ]: The max angle.startLength
[ number ]: The start length.endLength
[ number ]: The end length.