Zephos Posted September 25, 2018 Share Posted September 25, 2018 Hi all. I am trying to transition between Universal and ArcRotate cameras seamlessly, but haven't been able to figure it out. I want the cameras to show the exact same scene at the time of the switch, and all I really need to change is the control system so I can go from freely flying around to orbiting an object when you select it, and then back to free flight when you deselect it. I have a playground with two spheres you can select and the cameras automatically switch, and you can deselect them by clicking them again. As you will see, if you move the cameras around at all the switch between them gets real janky and sometimes you can't even see the spheres after a switch, even though I am trying to sync the camera positions and targets as best as I know how. I must be missing something. Here is the PG: http://www.babylonjs-playground.com/index.html#VDZ7IF#1 Thanks a lot in advance! Quote Link to comment Share on other sites More sharing options...
Guest Posted September 25, 2018 Share Posted September 25, 2018 Hello! I found a few problem: - not detaching camera before switching - not copying the target and the position correctly Fix: http://www.babylonjs-playground.com/index.html#VDZ7IF#2 Quote Link to comment Share on other sites More sharing options...
Zephos Posted September 25, 2018 Author Share Posted September 25, 2018 Thanks Deltakosh, I tried your playground and it is better but it still doesn't seem to behave correctly. If you select a sphere to switch to the orbit camera, and then rotate the the camera around a fair bit, then deselect the sphere, the view changes when the camera switches again. i would like the view to stay the same. Is there any way to accomplish this? Thanks again. Quote Link to comment Share on other sites More sharing options...
Guest Posted September 25, 2018 Share Posted September 25, 2018 Here we are: http://www.babylonjs-playground.com/index.html#VDZ7IF#3 (setTarget on an universalcamera will update rotation property but it needs to get the current position first) Quote Link to comment Share on other sites More sharing options...
Zephos Posted September 25, 2018 Author Share Posted September 25, 2018 Deltakosh, Thank you so much. That's exactly what I needed. I looked around the documentation and tutorials to help me solve this but didn't find anything that helped. Is this an area that is not documented well or did I just not find it? I guess I am talking about the seTarget function mainly, as I have no idea what it does differently than simply setting the target property, etc. I have the same question regarding setPosition() too. Also, the Babylon 101 tutorials make it sound like you don't have to detach controls before switching, and why do I need to clone the position and target vectors? Thanks Quote Link to comment Share on other sites More sharing options...
Guest Posted September 25, 2018 Share Posted September 25, 2018 The clone is not necessary but it is more a good habit For documentation, this specific topic you mentioned (about setTarget) could clearly be mentioned in the 101. Feel free to help us with a tiny PR on the documentation site Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.