> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-es/scenes-sdk7/interactividad/avatares/move-player.md).

# Mover al jugador

Teletransporta al jugador, o haz que camine hasta una nueva posición dentro de tu escena

Para cambiar la posición del jugador en la escena, usa la `movePlayerTo()` función. Úsala para reaparecer jugadores, configurar puntos de control o hacer que un jugador camine hasta un punto como parte de una cinemática.

{% hint style="info" %}
**💡 Consejo**: La forma más sencilla de mover al jugador es usar la [Scene Editor en Creator Hub](/creator/content-creator-es/scene-editor/primeros-pasos/about-editor.md). Usa la acción sin código **Mover al jugador** o **Mover al jugador aquí** Acciones, consulta [Convierte cualquier item en smart](/creator/content-creator-es/scene-editor/interactividad/make-any-item-smart.md).
{% endhint %}

Esta función toma un objeto con las siguientes propiedades:

* `newRelativePosition`: Dónde posicionar al jugador, expresado como un Vector3.
* `cameraTarget`: (opcional) La dirección hacia la que hacer que apunte la cámara, expresada como un Vector3 que representa las coordenadas de un punto del espacio al que mirar. Si no se proporciona un valor, la cámara mantendrá la misma rotación que antes de moverse.
* `avatarTarget`: (opcional) La dirección hacia la que hacer que apunte el avatar, expresada como un Vector3 que representa las coordenadas de un punto del espacio al que mirar. Si no se proporciona un valor, el avatar mantendrá la misma rotación que antes de moverse. Si el jugador está en modo de cámara en primera persona, la rotación de la cámara y del avatar es la misma.
* `duración`: (opcional) Cuánto debe durar la transición, en segundos. Si no se proporciona un valor, la transición ocurrirá al instante. Si se proporciona una duración, el avatar caminará o correrá hasta esta nueva posición.

{% hint style="warning" %}
**📔 Nota**: Durante la transición, el avatar no se ve afectado por los colliders, por lo que puede atravesar objetos.
{% endhint %}

```ts
import { movePlayerTo } from '~system/RestrictedActions'

// crear entidad
const myEntity = engine.addEntity()
MeshRenderer.setBox(myEntity)
MeshCollider.setBox(myEntity)

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

// darle comportamiento a la entidad
pointerEventsSystem.onPointerDown(
	{
		entity: myEntity,
		opts: { button: InputAction.IA_POINTER, hoverText: 'Clic' },
	},
	function () {
		// reaparecer al jugador
		movePlayerTo({
			newRelativePosition: Vector3.create(1, 0, 1),
			cameraTarget: Vector3.create(8, 1, 8),
			avatarTarget: Vector3.create(8, 1, 8),
		})
	}
)
```

El movimiento del jugador ocurre al instante, sin pantallas de confirmación ni transiciones de cámara.

{% hint style="warning" %}
**📔 Nota**: Los jugadores solo pueden moverse si ya están dentro de los límites de la escena, y solo pueden moverse a ubicaciones que estén dentro de los límites de la escena. No puedes usar `movePlayerTo()` para transportar a un jugador a otra escena. Para mover a un jugador a otra escena, consulta [Teleports](/creator/content-creator-es/scenes-sdk7/interactividad/external-links.md#teleports).
{% endhint %}

El `movePlayerTo()` la función admite await, así que si el movimiento tiene una duración, puedes usar `await` para esperar a que el jugador llegue a su destino.

```ts
import { movePlayerTo } from '~system/RestrictedActions'

pointerEventsSystem.onPointerDown(
	{
		entity: myEntity,
		opts: { button: InputAction.IA_POINTER, hoverText: 'Clic' },
	},
	async function () {
		await movePlayerTo({
			newRelativePosition: Vector3.create(1, 0, 1),
			cameraTarget: Vector3.create(8, 1, 8),
			avatarTarget: Vector3.create(8, 1, 8),
			duration: 2,
		})
	}
)
```

Si el jugador intenta moverse durante la duración de su transición, la transición se interrumpirá y la `movePlayerTo` función nunca se resolverá. Puedes evitar este comportamiento deshabilitando todas las entradas mientras la transición está en curso usando el `InputModifier` componente, consulta [Restringir la locomoción](/creator/content-creator-es/scenes-sdk7/interactividad/avatares/locomotion.md#restrict-locomotion).

```ts
import { movePlayerTo } from '~system/RestrictedActions'
import {InputModifier, engine} from '@dcl/sdk/ecs'

pointerEventsSystem.onPointerDown(
	{
		entity: myEntity,
		opts: { button: InputAction.IA_POINTER, hoverText: 'Clic' },
	},
	async function () {

		// deshabilitar todas las entradas
		InputModifier.create(engine.PlayerEntity, {
			mode: InputModifier.Mode.Standard({
				disableAll: true,
			}),
		})

		// mover al jugador
		await movePlayerTo({
			newRelativePosition: Vector3.create(1, 0, 1),
			cameraTarget: Vector3.create(8, 1, 8),
			avatarTarget: Vector3.create(8, 1, 8),
			duration: 2,
		})

		// habilitar todas las entradas
		InputModifier.deleteFrom(engine.PlayerEntity)
	}
)
```

{% hint style="warning" %}
**📔 Nota**: Además, el resultado del await puede almacenarse para evaluar su `éxito` propiedad para saber si el movimiento se interrumpió (por ejemplo, por movimiento de entrada) o se completó correctamente.
{% endhint %}

{% hint style="info" %}
**💡 Consejo**: Para mover a un jugador a una escena diferente, o a diferentes coordenadas en el mapa de Genesis City, consulta [Teleports](/creator/content-creator-es/scenes-sdk7/interactividad/external-links.md#teleports).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-es/scenes-sdk7/interactividad/avatares/move-player.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
