First Person Controller API

advanced scripting

Voxel Play 3 · Scripting / API

Overview

Properties and methods accessible through VoxelPlayFirstPersonController.instance.

Properties

  • bool crosshairOnBlock - Whether the crosshair currently targets an accessible voxel (determined by the hit range in the Player component)
  • VoxelHitInfo crosshairHitInfo - Provides information about the voxel under the crosshair
  • bool isFlying - Player is flying
  • bool isMoving - Player is moving (walk or run)
  • bool isRunning - Player is running
  • bool isInWater - Player is in water (surface or underwater)
  • bool isSwimming - Player is on water surface
  • bool isUnderwater - Player is below water surface
  • bool isGrounded - Player is on ground
  • bool isCrouched - Player is crouched
  • bool isUnderground - Player is underground or undercover
  • VoxelDefinition voxelUnder - Voxel under the character feet
  • bool cameraOrbitMode - Camera orbit mode state
  • float cameraOrbitModeSpeed - Speed of orbit mode (default 4)
  • float cameraOrbitModeDistanceV - Vertical distance in orbit mode (default 40)
  • float cameraOrbitModeDistanceH - Horizontal distance in orbit mode (default 35)

Movement Settings

  • float walkSpeed - Walk speed (default 5)
  • float runSpeed - Run speed (default 10)
  • float flySpeed - Fly speed (default 20)
  • float swimSpeed - Swim speed (default 3.7)
  • float jumpSpeed - Jump speed (default 10)
  • bool canClimb - Whether the player can climb (default true)
  • float climbMaxStepHeight - Max step height for climbing (default 1.1)

Methods

  • SetCameraOrbitMode(bool state) - Transitions between free camera movement and orbit mode, enabling the camera to rotate around a target position. The demo scene "Colorizer" demonstrates this feature.
  • AddExternalForce(Vector3 force) - Add a temporary push force to the character
  • MoveTo(Vector3 newPosition) - Move the character to a specific position
  • Move(Vector3 deltaPosition) - Move the character by a delta position
  • SetFreeCamMode(bool enableFreeCam) - Enable/disable free camera mode
  • ResetCrosshairPosition() - Reset crosshair to default position
  • ForceUpdateCrosshair(int frames = 2) - Force crosshair update for N frames
  • ToggleCharacterController(bool state) - Enable/disable the CharacterController component
  • ToggleCharacterLight() - Toggle character light on/off
  • ToggleCharacterLight(bool state) - Set character light state
  • SetFootstepSounds(AudioClip[] footStepsSounds, AudioClip jumpSound, AudioClip landSound) - Set custom footstep sounds

Events

  • OnVoxelEnter - Triggered when player enters a voxel if that voxel definition has triggerEnterEvent = true
  • OnVoxelWalk - Triggered when a player walks over a voxel if that voxel definition has triggerWalkEvent = true
Was this page helpful?