Content Creators
Move a player

Move a player

To change the player’s position in the scene, set the position of the Transform component for the engine.PlayerEntity entity.

const playerTransform = Transform.getMutable(engine.PlayerEntity)
playerTransform.position = {x: 1, y: 10, z: 1}

The engine.PlayerEntity entity may not be available to modify while the scene is being loaded. The example below performs the player’s movement after the scene is loaded, each time an entity is clicked.

// create entity
const myEntity = engine.addEntity()
MeshRenderer.setBox(myEntity)
MeshCollider.setBox(myEntity)

Transform.create(myEntity, {
  position: {x:4, y:1, z:4}
})

// give entity behavior
pointerEventsSystem.onPointerDown(
  entity,
  function () {
     respawnPlayer()
  },
  {
    button: InputAction.IA_POINTER,
    hoverText: 'Click'
  }
)

// function to handle respawn
function respawnPlayer(){
 const playerTransform = Transform.getMutable(engine.PlayerEntity)
	  playerTransform.position = {x: 1, y: 10, z: 1}
}

The player’s movement occurs instantly, without any confirmation screens or camera transitions.

📔 Note: Players can only be moved if they already are standing inside the scene’s bounds, and can only be moved to locations that are inside the limits of the scene’s bounds. You can’t use movePlayerTo() to transport a player to another scene. To move a player to another scene, see Teleports.

You must first add the ALLOW_TO_MOVE_PLAYER_INSIDE_SCENE permission to the scene.json file before you can use this feature. If not yet present, create a requiredPermissions property at root level in the JSON file to assign it this permission.

"requiredPermissions": [
    "ALLOW_TO_MOVE_PLAYER_INSIDE_SCENE"
  ],

See Required permissions for more details.

📔 Note: To prevent abusive behavior that might damage a player’s experience, the ability to move a player is handled as a permission. Currently, this permission has no effect in how the player experiences the scene. In the future, players who walk into a scene with this permission in the scene.json file will be requested to grant the scene the ability to move them.