satguru Posted January 17, 2016 Share Posted January 17, 2016 I have an ArcRotateCamera, a box and a sphere. As I rotate the camera I want the sphere to be at always a fixed distance from the camera and between the camera and the box , (that is on a line joining the camera and the box). In other words it should look like the sphere is stuck to the box. Every render cycle I calculate the position of the sphere based on the camera and box position and set the position of the sphere to that. But for some reason there is a lag between the movement of the camera and the sphere. This is due to the camera inertia. If I set the inertia to zero the lag decreases considerably but there is still some. Here is an example http://www.babylonjs-playground.com/#1Z1Q0D#1 Any idea how i can prevent the lag? Regards Satguru Quote Link to comment Share on other sites More sharing options...
Temechon Posted January 17, 2016 Share Posted January 17, 2016 Is this example is ok for you ? I didn't fix your code but took a different approach for the wanted behaviour : http://www.babylonjs-playground.com/#1Z1Q0D#2 Quote Link to comment Share on other sites More sharing options...
satguru Posted January 17, 2016 Author Share Posted January 17, 2016 @Temechon, Thanks for the solution. It works for me except for the fact that the scale of the object, sphere in this case, changes with the distance from the camera. So I did end up using this approach but in addition I also change the scale of the object with the distance - the farther away the larger the scale - so the size always appear the same. As an FYI, I am building a small editor and the sphere is actually a 3 axis object which can be used to position things. I am happy with this work around but I am still curious about the lag. Looks like the camera position is not updated during the render cycle. The position which my code gets during the render cycle seems to be an older value - maybe the camera keeps moving while my render loop code is executing. Does the camera moves in a different thread? Regards Satguru 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.