In the documentation for Trail Mesh Trail Mesh | Babylon.js Documentation some example code is provided.
At the beginning, alpha is declared as const alpha = Math.PI;
The scene freezes up when I add this code:
observer = scene.onBeforeRenderObservable.add(animate);
function animate() {
alpha += Math.PI/120;
cube.position.x = Math.sin(alpha) * 10;
cube.position.y = Math.cos(alpha) * 10;
cube.rotation.x = (Math.PI * alpha) / 2;
cube.rotation.y = alpha;
}
yielding an error in the browser console about assignment to a constant variable. I believe alpha has to be declared as let alpha = ...
for the code to work.
Additionally, I do not know why observer
can work in this case, even though it has not been declared. If anyone can offer some insight, that would be very helpful.