[SOLVED] Problem zooming, Teleport to a position iin another scene

Hello!

I’m designing a small city where the user would be able to walk around and go inside of the buildings too. Here is the link of the project: PlayCanvas | HTML5 Game Engine

I created a door (trigger), when the person hit the door, he goes inside of the building (which is in another scene). The problem is, I use the scroll wheel of the mouse to zoom in the map, it works well but when I go from a scene to another one, I have this message: “Uncaught TypeErro: Cannot read property ‘fov’ of undefined and I can’t zoom anymore”. I tried to do some modifications but it doesn’t work. Can someone help me?

And I wanted to know how can I teleport a person to a certain position in another scene? As I’m new to playcanvas, I just know how to switch scenes and teleport a person to a position in the same scene.

Thank you for your help! :slight_smile:

P.S. I put the door (the small white box) in the center of the map

Hi, do you have to script for the zoom also in the other scene? I tried a bit going around and i have 2 things to point out 1st some texture of building is too low detailed 2nd the point of view of camera is too low, i feel like a dog going around. Is a nice work! keep going :slight_smile:

When you load another scene do you remove previous one?
If you remove camera but still have event for mousewheel it will not be able to deal with that camera as it is removed. So if you remove previous camera, make sure you remove event listener for mouse wheel.

Yes, I delete the previous scene before loading the other one.
Thank you very much! When I remove the event listener for mouse wheel before the teleportation, it works! :slight_smile:

Last question: is it possible to teleport the player to a certain location of the other scene directly? But not just load the new scene. As the player is going out of the building through the door, I want him to be teleported in front of the building but not appearing in the middle of the map.

I don’t like multi-scene workflow. As it does not preserves many things.
Basically if your player object is different in both scenes, then you have to simply account for that and move it when and where needed.

I like when my hierarchy is single, and I personally use enable/disable of entities, that makes my life easier, as it is persistent hierarchy.

Yes, I scripted for the zoom in the other scene too because I want the user to be able to zoom in all the maps. And thank you for testing the map, I will take notes of these remarks.

I would really like to use only one scene too but I still have a lot of 3D models (buidings and the inside) to import on playcanvas. It will be probably heavy so I’m afraid that WebGL will hit a snag (as you can read on this toipc: Importing fbx files, WEBGL hit a snag). I think that it will not appear if I split my models into different scenes. Or what do you recommend to me?

An easy way to do this would be to have a spawn point in each scene which would be something like an Entity with a special name or a special script which sets the position of your player at its location when a new scene is loaded.

After loading a new scene you could search for the spawn point in the newly loaded scene and move the player there.

Thank you! That’s a great idea! But as I’m really new to playcanvas, I don’t know how to set the position of the player in the scene when the new scene is loaded. I tried the function"setPosition", it didn’t work and the function"translate" just make the player move when the program runs but it doesn’t really change his position.

Hi everyone! For the teleportation, I was thinking about editing the position of the person in the first scene (outside of the building) before loading the other one (inside of the building), so when I come back from the inside scene and load the outside one, the position of the person would be in front of the door. For that, I used the function “setPosition” but it doesn’t work, when I load the inside scene and come back to the outside one, I get the same scene as the beginning (the person appear in the middle of the map and not in front of the door). Can someone tell me how to programmatically edit the first scene and save it?

When you reload scene, it will not preserve old data, as you destroyed old scene.

I would suggest trying another approach here: create inside of building as part of main scene, just as separate entity, and simply enable/disable entity when needed.
Doing so might simplify whole process of managing state.

thank you for this suggestion, I think it’s the only solution. I’m going to do that