Reset scene in typescript

I’m currently making a parkour game for an assignment and how can I reset the scene after touching the floor?

let cam= Scene.getItem(“8sxGJAo3”) as CameraItem; //define variables
let lava = Scene.getItem(“jOWy0c4V”) as Cuboid;

cam.onCollisionEnter((obj)=>{
if(obj==lava){

    **Space.goToScene(3)**

//Reset scene instead of changing scene?
}

Hi @Monib_Niazi,

You should be able to use Space.goToScene() to go to the scene you are on. Note that scenes are zero-indexed, so the first scene would be Space.goToScene(0).

However, a more efficient approach would be to store the initial Camera location in a variable and change the position to that variable’s value when you collide with the lava.

Hope that helps! Let me know if you have any further questions about this. If this solves your problem, please make this post as the Solution.

Many thanks,
Geoff @ TechLeap

1 Like

I tried it and it doesn’t work. If I were in scene “0” and I put the command Space.goToScene(0) then nothing would happen. It would only work if I were to change scenes.

I am currently using the second approach but it bugs sometimes and stops at an obstacle in the way. I was also thinking of making a duplicate and switching scenes every time I fall in the lava. However, that isn’t very efficient.

Yes, sorry, I checked, and the restartScene function isn’t available in the public API.

Use the following to prevent obstacles getting in the way when returning to the home position:

let cam_pos = cam.transform.position;
let cam_rot = cam.transform.rotation;

cam.onCollisionEnter((obj)=>{
    if(obj === lava){
        cam.transform.position = cam_pos;
        cam.transform.rotation = cam_rot;
    }
});

Hope that helps! Let me know if you have any further questions about this. If this solves your problem, please mark this post as the Solution.

Many thanks,
Geoff @ TechLeap