Class: Voxel

Class contents

Methods list

These are special functions (or methods) that you may call on the object. these functions typically instruct the object to perform a certain operation.

Public properties list

Properties are attributes of the object, this directly affect the object in question. Some of them can be read or written, or both.
Name Type Description
name string A user defined name for the voxel
sticky boolean (Default : True) This causes players to stick to the cube when it moves (up-to a maximum velocity)
title string A title which can be displayed on the cube, useful for on-cube text
titlePosition enum The visibility and position of the title
voxelTitlePosition.notVisible - title not appear (invisible)
voxelTitlePosition.onVoxel - Title will appear on the surface of the voxel (centered)
voxelTitlePosition.aboveVoxel - The title will float about the voxel (exact center of cube)
sticky boolean (Default : True) This causes players to stick to the cube when it moves (up-to a maximum velocity)
x float The x world position
y float The y world position
z float The z world position

Events list

Events are functions you add to your objects, that will be called by Cubiverse when certain things (events) occur.

Class Information

Constructor

new Voxel()

This is a representation of a moving voxel within Cubiverse.

Your game world will contain thousands of voxels, but until you actually add some code to one (or spawn one dynamically) then there will be no server-side representation of it.

Properties:

Name Type Description
name string A user defined name for the voxel
sticky boolean (Default : True) This causes players to stick to the cube when it moves (up-to a maximum velocity)
title string A title which can be displayed on the cube, useful for on-cube text
titlePosition enum The visibility and position of the title
voxelTitlePosition.notVisible - title not appear (invisible)
voxelTitlePosition.onVoxel - Title will appear on the surface of the voxel (centered)
voxelTitlePosition.aboveVoxel - The title will float about the voxel (exact center of cube)
sticky boolean (Default : True) This causes players to stick to the cube when it moves (up-to a maximum velocity)
x float The x world position
y float The y world position
z float The z world position
Important:
  • You cannot instigate a voxel directly from normal Java-script code, it can only be created by adding a script to any in-game voxel or by spawning a dynamic voxel using World.spawnVoxel()

Methods

delete()

Marks the voxel for deletion, it will be removed during the next "server tick"

moveCubeY(distance, duration, smooth)

Moves the cube in the Y directon

Please ensure that the world position given has enough room for the player to teleport to; you do not want them stuck inside the world.

Speed Consideration: Do not move the voxel too quickly, otherwise players will fall through the voxel. As all players experience different latencies you should generally ensure that you move no faster than 2 units per second.

Parameters:
Name Type Description
distance float The amount (in world units) to move the cube (positive or negative)
duration float The time taken to make such a movement
smooth boolean (not supported) True - smooth the movement as the voxel reaches it's final position
Example
myVoxel.moveCubeY(10, 15, false) ;

teleportPlayer(x, y, z)

Teleports the player to a given world position

Please ensure that the world position given has enough room for the player to teleport to; you do not want them stuck inside the world.

Parameters:
Name Type Description
x float The x world position where the player is to be teleported
y float The y world position where the player is to be teleported
z float The z world position where the player is to be teleported
Example
myVoxel.teleportPlayer(50, 23, 58) ;

Events

onTouched

Called when a player touches any face of the voxel

This event is trigger EVERY server tick that a player is touching the voxel. This event is called continously (per server tick) whilst one (or more) players are on top of the cube. You should write code that handles the event firing every server tick AND getting multiple events (per server tick) from multiple players!

Single Shot: If you return 'false' from the event then the function will be called only once (regardless of which player triggered it)

Parameters:
Name Type Description
playerObject object The actual playerObject who walked on this voxel
Example
// Print the player nickName who touched on this voxel
MyVoxel.onTouched = function( playerObject )
{
    log("MyVoxel.onTouched() called with nick : " + playerObject.nickName) ;
}

onWalkOn

Called when a player walks on the voxel

This event is trigger EVERY server tick that a player is on top of the voxel. This event is called continously (per server tick) whilst one (or more) players are on top of the cube. You should write code that handles the event firing every server tick AND getting multiple events (per server tick) from multiple players!

Single Shot: If you return 'false' from the event then the function will be called only once (regardless of which player triggered it)

Parameters:
Name Type Description
playerObject object The actual playerObject who walked on this voxel
Example
// Print the player nickName who walked on this voxel
MyVoxel.onWalkOn = function( playerObject )
{
    log("MyVoxel.onWalkOn() called with nick : " + playerObject.nickName) ;
}