# Move on ground With the help of cursor

**URL:** <https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435>\
**Category:** Questions\
**Created:** [August 30, 2021, 1:32pm UTC](https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435 "2021-08-30T13:32:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayakannan](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jayakannan](https://forum.babylonjs.com/u/jayakannan)\
**Post date:** [August 30, 2021, 1:32pm UTC](https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435/1 "2021-08-30T13:32:30Z")

</div>

Hi,  
I am in need of a similar experience like this [Multilevel Full Rehab - framing stage - 42 Summer Street - Matterport 3D Showcase](https://my.matterport.com/show/?m=JDaba3GGAW6)  
While hover the mouse on a ground mesh, there should be an image kind of marker. When I click on the ground, the camera should move to that place. Please have a look into the shared link.

Thanks,  
Jaya kannan K R.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 30, 2021, 5:12pm UTC](https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435/2 "2021-08-30T17:12:09Z")

</div>

This sounds extremely similar to the VR teleportation feature @RaananW ?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [August 30, 2021, 5:58pm UTC](https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435/3 "2021-08-30T17:58:00Z")

</div>

This is probably very close to the hotspot teleportation implementation. You will need to change the cursor yourself, and will need to add images (or a marker) to the spots, but other than that this is implemented (when in VR):

> **[WebXR Selected Features | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/webXR/WebXRSelectedFeatures#snap-to-hotspots)**
>
> Learn about key WebXR features in Babylon.js.

---

<div class="post-metadata">

**Author:** ![jayakannan](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jayakannan](https://forum.babylonjs.com/u/jayakannan)\
**Post date:** [August 31, 2021, 4:10am UTC](https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435/4 "2021-08-31T04:10:57Z")

</div>

First of all thanks for your replies @sebavan @RaananW . @sebavan You are right, this is similar to the teleportation in VR. I need the same in WebGL too. @RaananW I am not sure about your suggestion on it. I am sharing another sample of it which is a webgl sample contains the same operation.

> **[WebVR Showroom](https://showroom.littleworkshop.fr/)**
>
> Step inside a virtual showroom built with WebGL and WebVR.

Just go through it and click “ENTER THE SHOWROOM” button and move the cursor on the floor, you will see the operation.

Thanks,  
Jaya Kannan K R.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [August 31, 2021, 2:00pm UTC](https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435/5 "2021-08-31T14:00:52Z")

</div>

This is something you will be able to implement on your own. The pointer selection feature allows you to know when the pointer collides with any mesh that is pickable. When when the pointer selection points at a specific mesh, you will want to set a different behavior. One of the behaviors is - when the p[ointer select is selecting the ground mesh, show a pointer mesh in the point defined in the picking info

---

<div class="post-metadata">

**Author:** ![jayakannan](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jayakannan](https://forum.babylonjs.com/u/jayakannan)\
**Post date:** [September 2, 2021, 10:03am UTC](https://forum.babylonjs.com/t/move-on-ground-with-the-help-of-cursor/23435/6 "2021-09-02T10:03:07Z")

</div>

Done.  
I have shared my script below

```auto
let mouse_on_ground = false;
    let canvas = document.getElementById("renderCanvas");
    let engine = new BABYLON.Engine(canvas, true, {
      preserveDrawingBuffer: true,
      stencil: true,
      disableWebGL2Support: false,
    });
    engine.setHardwareScalingLevel(0.5);
    const scene = new BABYLON.Scene(engine);
    const camera = new BABYLON.ArcRotateCamera(
      "camera",
      Math.PI / 2,
      Math.PI / 2.5,
      3,
      new BABYLON.Vector3(0, 0, 4),
      scene
    );
    scene.shadowsEnabled = true;
    camera.wheelPrecision = 20;
    camera.position = new BABYLON.Vector3(30,1,0);
    camera.fov = 0.5;
    camera.inertia = 0.8;
    camera.target = new BABYLON.Vector3(0,0,0);
    camera.attachControl(canvas, true);

    // const light = new BABYLON.HemisphericLight(
    // "light",
    // new BABYLON.Vector3(0, 1, 0),
    // scene
    // );
    let json_data;
    let material_data;

    var hdrTexture = new BABYLON.CubeTexture.CreateFromPrefilteredData(
      "assets/textures/sample.env",
      scene
    );
    scene.environmentTexture = hdrTexture;
    scene.environmentIntensity = 0.4;
    const ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 40, height: 10 });
    let material_gnd = new BABYLON.PBRMaterial("ground_material", scene);

    const cursor_part = BABYLON.MeshBuilder.CreateGround("cursor_part", { width: 2, height: 2 });
    const cursor_part_material = new BABYLON.PBRMaterial("cursor_part_material", scene);
    cursor_part_material.unlit = true;
    cursor_part_material.albedoColor = new BABYLON.Color3(1, 0, 0);
    cursor_part_material.backFaceCulling = false;
    cursor_part_material.albedoTexture = new BABYLON.Texture(
      "./assets/textures/ring.webp",
      scene
    );
    cursor_part_material.albedoTexture.uScale = 1;
    cursor_part_material.albedoTexture.vScale = -1;
    cursor_part_material.opacityTexture = new BABYLON.Texture(
      "./assets/textures/ring.webp",
      scene
    );
    cursor_part_material.opacityTexture.uScale = 1;
    cursor_part_material.opacityTexture.vScale = -1;

    cursor_part.material = cursor_part_material;

    ground.material = material_gnd;
    ground.position.y -= 2;
    // scene.createDefaultSkybox(hdrTexture, true, 10000);
    $.getJSON("assets/json/materials.json", function (json) {
      let json_data = json;
      material_data = json_data.Materials;
      start();
    });

    var defaultPipeline = new BABYLON.DefaultRenderingPipeline(
      "default",
      true,
      scene,
      [camera]
    );
    defaultPipeline.fxaaEnabled = true;

    function start() {
      let ground_plane = scene.getMeshByName("ground");
      interfacing_action_manager = new BABYLON.ActionManager(scene);
      interfacing_action_manager.registerAction(
        new BABYLON.ExecuteCodeAction(
          BABYLON.ActionManager.OnPointerOverTrigger,
          function (ev) {
            let mesh_under_cursor = ev.meshUnderPointer.name;
            mouse_on_ground = true;
          }
        )
      );
      interfacing_action_manager.registerAction(
        new BABYLON.ExecuteCodeAction(
          BABYLON.ActionManager.OnPointerOutTrigger,
          function (ev) {
            mouse_on_ground = false;
          }
        )
      );
      ground_plane.actionManager = interfacing_action_manager;

    }

    scene.onPointerMove = function (event, pickResult) {
      if (mouse_on_ground) {
        cursor_part.position = new BABYLON.Vector3(pickResult.pickedPoint.x, pickResult.pickedPoint.y + 0.1, pickResult.pickedPoint.z);
        
      }
    }
    scene.onPointerDown = function (event, pickResult) {
      if (mouse_on_ground) {
        let camPosTo = new BABYLON.Vector3(pickResult.pickedPoint.x, pickResult.pickedPoint.y + 1, pickResult.pickedPoint.z);
        camera.position = camPosTo;
        camera.target = new BABYLON.Vector3(pickResult.pickedPoint.x,pickResult.pickedPoint.y + 1,pickResult.pickedPoint.z+1)
      }
    }

    engine.runRenderLoop(function () {
      if (scene && scene.activeCamera) {
        scene.render();
      }
    });
    window.addEventListener("resize", function () {
      engine.resize();
    });

```
