Why does the mesh disappear on the second click

When I double-click in one place in the scene, the grid disappears, and how to make a smooth transition :woozy_face:

sounds impossible to know without a Playground to repro ?

https://playground.babylonjs.com/#20OAV9#4676

Hey strelok93,

 function runDeg(coordsmesh, coordspoint) {
        var a, b;
        var firstCoords = coordsmesh, secondCoords = coordspoint;
        a = firstCoords[0] - secondCoords[0];
        b = firstCoords[1] - secondCoords[1];
        var rad = Math.arcctg(a / b);
        console.log(rad)
        var deg = rad * 180 / Math.PI;
        if (firstCoords[1] >= secondCoords[1]) {
            var deg = rad * 180 / Math.PI - 180;
        }
        return deg;
    }

On your second click at the same point, coordmesh and coordspoint are equal. Ergo, rad = undefined. Ergo, rotation of the mesh is NaN. Thus, making the mesh disappear.

A simple equality check should fix the problem.

  if(personage.position.x !=pickResult.pickedPoint.x && personage.position.z!=pickResult.pickedPoint.z)
            {
            dengil = runDeg([personage.position.x, personage.position.z], clcPos)
            personage.rotation.y = -(dengil - 90) * (Math.PI / 180);
            personage.position.x = clcPos[0];
            personage.position.z = clcPos[1];
            }
1 Like

Thank you

1 Like