sm.camera

The camera library contains methods related to the localPlayer's camera view.

In first-person view the camera is located inside the player's head, whereas in third-person view it floats behind them.

This library can only be used on the client.

Constants:

Functions:

  • cameraSphereCast
  • getCameraPullback
  • getCameraState
  • getDefaultFov
  • getDefaultPosition
  • getDefaultRotation
  • getDirection
  • getFov
  • getPosition
  • getRight
  • getRotation
  • getUp
  • setCameraPullback
  • setCameraState
  • setDirection
  • setFov
  • setPosition
  • setRotation
  • setSeatLockedCameraPullback
  • setSeatLockedCameraUpOffset
  • setSeatLockedLocalDirection
  • setSeatLockedLocalUp
  • setShake
  • setUnseatDirection

  • sm.camera.state table

    Camera states are used to specify how the camera will view the world. The default state is meant for normal gameplay and the scripted states are meant to be used in cutscenes or interactables.

    The states are:

    default 1
    cutsceneFP 2
    cutsceneTP 3
    forcedTP 4
    gyroSeatFP 5
    gyroSeatTP 6
    scriptedTP 7
    seatLockedCamera 8

    sm.camera.cameraSphereCast(radius, start, direction)

    Client only

    Performs a distance convex sweep with the shape of a sphere, from a position with a given direction.

    Parameters:

    TypeNameDescription
    numberradiusThe radius of the cast sphere
    Vec3startThe start position.
    Vec3directionThe cast direction and range.

    Returns:

    TypeDescription
    numberThe fraction of the distance reached until collision.

    sm.camera.getCameraPullback()

    Client only

    Returns the camera's zoom step.

    Returns:

    TypeDescription
    numberstep How far away the camera is from the player while standing
    numberseatedStep How far away the camera is from the player while seated

    sm.camera.getCameraState()

    Client only

    Gets the camera's control state.

    Returns:

    TypeDescription
    integerstate How the camera is moved. (See sm.camera.state)

    sm.camera.getDefaultFov()

    Client only

    Returns the camera's default field of view angle.

    Returns:

    TypeDescription
    numberThe field of view.

    sm.camera.getDefaultPosition()

    Client only

    Returns the world position where the camera should be by default.

    Returns:

    TypeDescription
    Vec3The camera's world position.

    sm.camera.getDefaultRotation()

    Client only

    Returns the world rotation where the camera should be by default.

    Returns:

    TypeDescription
    QuatThe camera's default world rotation.

    sm.camera.getDirection()

    Client only

    Returns the direction the camera is aiming.

    Returns:

    TypeDescription
    Vec3The direction of the camera's aim.

    sm.camera.getFov()

    Client only

    Returns the camera's field of view angle.

    Returns:

    TypeDescription
    numberThe field of view.

    sm.camera.getPosition()

    Client only

    Returns the world position of the camera.

    Returns:

    TypeDescription
    Vec3The camera's world position.

    sm.camera.getRight()

    Client only

    Returns the right-vector perpendicular to the camera's aim.

    Returns:

    TypeDescription
    Vec3The right-vector of the camera's aim.

    sm.camera.getRotation()

    Client only

    Returns the world rotation of the camera.

    Returns:

    TypeDescription
    QuatThe camera's world rotation.

    sm.camera.getUp()

    Client only

    Returns the up-vector perpendicular to the camera's aim.

    Returns:

    TypeDescription
    Vec3The up-vector of the camera's aim.

    sm.camera.setCameraPullback(step, seatedStep)

    Client only

    Sets the camera's zoom step.

    Parameters:

    TypeNameDescription
    integerstepHow far away the camera is from the player while standing
    integerseatedStepHow far away the camera is from the player while seated

    sm.camera.setCameraState(state)

    Client only

    Sets the camera's control state.

    Parameters:

    TypeNameDescription
    integerstateHow the camera is moved. (See sm.camera.state)

    sm.camera.setDirection(direction)

    Client only

    Sets the direction the camera is aiming.

    Parameters:

    TypeNameDescription
    Vec3directionThe direction of the camera's aim.

    sm.camera.setFov(FOV)

    Client only

    Sets the camera's field of view angle.

    Parameters:

    TypeNameDescription
    numberFOVThe field of view.

    sm.camera.setPosition(position)

    Client only

    Sets the world position of the camera.

    Parameters:

    TypeNameDescription
    Vec3positionThe camera's world position.

    sm.camera.setRotation(rotation)

    Client only

    Sets the rotation of the camera.

    Parameters:

    TypeNameDescription
    QuatrotationThe rotation of the camera.

    sm.camera.setSeatLockedCameraPullback(pullback)

    Client only

    Sets the camera pullback distance for the seatLockedCamera camera state.

    When greater than zero the camera is pulled back from the seat origin along the camera direction.

    Parameters:

    TypeNameDescription
    numberpullbackThe pullback distance.

    sm.camera.setSeatLockedCameraUpOffset(upOffset)

    Client only

    Sets the camera up offset for the seatLockedCamera camera state.

    Parameters:

    TypeNameDescription
    numberupOffsetThe up offset in local space.

    sm.camera.setSeatLockedLocalDirection(localDirection)

    Client only

    Sets the local direction for the camera when using the seatLockedCamera camera state.

    The direction is in the seat's local space and will be transformed by the interpolated seat rotation.

    Parameters:

    TypeNameDescription
    Vec3localDirectionThe local direction to face.

    sm.camera.setSeatLockedLocalUp(localUp)

    Client only

    Sets the local up vector for the camera when using the seatLockedCamera camera state.

    The up vector is in the seat's local space.

    Parameters:

    TypeNameDescription
    Vec3localUpThe local up direction.

    sm.camera.setShake(strength)

    Client only

    Sets the camera's level of camera shake.

    Parameters:

    TypeNameDescription
    numberstrengthThe camera shake strength.

    sm.camera.setUnseatDirection(worldDirection?)

    Client only

    Sets the world-space direction for the local player character to face when the player unseats. Cleared automatically when used or when entering a seat.

    Passing nil clears any previously set unseat direction.

    Parameters:

    TypeNameDescription
    Vec3worldDirection?The world-space direction to face on unseat. (optional)