diff --git a/docs/maps/entry-exit.md b/docs/maps/entry-exit.md index 6f98af93..7f74a46b 100644 --- a/docs/maps/entry-exit.md +++ b/docs/maps/entry-exit.md @@ -65,3 +65,20 @@ How to use entry point : * To enter via this entry point, simply add a hash with the entry point name to the URL ("#[_entryPointName_]"). For instance: "`https://workadventu.re/_/global/mymap.com/path/map.json#my-entry-point`". * You can of course use the "#" notation in an exit scene URL (so an exit scene URL will point to a given entry scene URL) + +## Defining destination point with moveTo parameter + +We are able to direct WOKA to the desired place immediately after spawn. To make users spawn on entry point and the go to the, for example, meeting room automatically, simply add `moveTo` as an additional parameter of URL: + +*Use default entry point* +``` +.../my_map.json#&moveTo=exit +``` +*Define entry point and moveTo parameter* +``` +.../my_map.json#start&moveTo=meeting-room +``` + +For this to work, moveTo must be equal to the layer name of interest. This layer should have at least one tile defined. In case of layer having many tiles, user will go to one of them, randomly selected. + +![](images/moveTo-layer-example.png) \ No newline at end of file diff --git a/docs/maps/images/moveTo-layer-example.png b/docs/maps/images/moveTo-layer-example.png new file mode 100644 index 00000000..66f5e3c6 Binary files /dev/null and b/docs/maps/images/moveTo-layer-example.png differ diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 3e53bb3f..c6df222c 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -1727,15 +1727,19 @@ ${escapedMessage} }); const moveToParam = urlManager.getHashParameter("moveTo"); if (moveToParam) { - const endPos = this.gameMap.getRandomPositionFromLayer(moveToParam); - this.pathfindingManager - .findPath(this.gameMap.getTileIndexAt(this.CurrentPlayer.x, this.CurrentPlayer.y), endPos) - .then((path) => { - if (path && path.length > 0) { - this.CurrentPlayer.setPathToFollow(path).catch((reason) => console.warn(reason)); - } - }) - .catch((reason) => console.warn(reason)); + try { + const endPos = this.gameMap.getRandomPositionFromLayer(moveToParam); + this.pathfindingManager + .findPath(this.gameMap.getTileIndexAt(this.CurrentPlayer.x, this.CurrentPlayer.y), endPos) + .then((path) => { + if (path && path.length > 0) { + this.CurrentPlayer.setPathToFollow(path).catch((reason) => console.warn(reason)); + } + }) + .catch((reason) => console.warn(reason)); + } catch (err) { + console.warn(`Cannot proceed with moveTo command:\n\t-> ${err}`); + } } } catch (err) { if (err instanceof TextureError) {