#Reseting scenario
9 messages · Page 1 of 1 (latest)
When the scene starts, save the original location to the userData. And when a reset occurs, change their location to originPosition.
Deletion and creation may cause performance problems. You can use visible property instead.
how do i save that thing?
const pos1 = new THREE.Vector2(0, 0);
const pos2 = new THREE.Vector2(0, -200);
const pos3 = new THREE.Vector2(0, 200);
const vel1 = new THREE.Vector2(0, 0);
const vel2 = new THREE.Vector2(-2, 0);
const vel3 = new THREE.Vector2(2, 0);
// Celestial Bodies initialization
const bodies = [
new CelestialBody(pos1, vel1, 1000, "white", scene),
new CelestialBody(pos2, vel2, 100, "red", scene),
new CelestialBody(pos3, vel3, 100, "teal", scene),
];
resetButton.addEventListener("click", () => {
cancelAnimationFrame(simulationId);
bodies.forEach((body) => {
scene.remove(body.mesh);
});
bodies.length = 0;
bodies.push(
new CelestialBody(pos1, vel1, 1000, "white", scene),
new CelestialBody(pos2, vel2, 100, "red", scene),
new CelestialBody(pos3, vel3, 100, "teal", scene)
);
paused = true;
startButton.textContent = "Resume Simulation";
});```
I would like to do this, but it isnt working
like, object keep moving from where they were
should i just better set each body to its original position?
@sinful oar
maybe i need to remove the body and not the mesh and add them back?
can you teach me about CelestialBody? If CelestialBody is a class, you just copy position of pos1, pos2, pos3.