Maria D

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. Hi! I'm trying to learn Babylon js and it's my first time using it ☺️. I'm doing a kind of planetary system and the planet's movement can be changed using a slider. I also draw a circle made with lines (the orbit) to show the path followed by the planet when the slider also changes. But I have problem: I don't know how to remove the previous drawn circle. So as a result when the planet changes its orbit, many circles are still drawn. Something like this: Here is a part of my code inside createScene function: //Creation of slider var slider = new BABYLON.GUI.Slider(); slider.minimum = 0; slider.maximum = 1; slider.value = 0; slider.paddingRight="10"; slider.horizontalAlignment= BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT; slider.height = "20px"; slider.width = "200px"; slider.top="10"; slider.color="blue"; for(var i = 0; i < div; i++){ divArray.push(Math.PI*(MitadDiv*i)); } slider.onValueChangedObservable.add(function(value) { e = value; a = Math.sqrt(-(b*b)/((e*e)-1)); text.text = "Excentricidad: "+(value); for(var i = 0; i < divArray.length; i++){ Path.push(new BABYLON.Vector3((b * Math.cos(divArray[i])+offset.x), (0+offset.y), (a * Math.sin(divArray[i])+offset.x))); } var lines = BABYLON.MeshBuilder.CreateDashedLines("lines", {points: Path, dashNb:500}, scene); }); guiManager.addControl(slider); scene.beforeRender = function () { planet.position = new BABYLON.Vector3((b * Math.cos(Math.PI*(MitadDiv*alpha))+offset.x), (0+offset.y), (a * Math.sin(Math.PI*(MitadDiv*alpha))+offset.x)); sun.rotate(BABYLON.Axis.Y, Math.sin(-0.001), BABYLON.Space.WORLD); planet.rotate(BABYLON.Axis.Y, Math.sin(2 * -Math.PI/180), BABYLON.Space.WORLD); alpha += 0.09; }; return scene; Thanks!!!