Camera that is parented to a camera lags behind

Hi!

This is sort of a follow up to my last issue. I have this playground: https://playground.babylonjs.com/#GQCSSP#2
It’s like a scope, with a cylinder, plane, and a camera. I’ll adjust everything later, but this is a sort of proof-of-concept for a sniper scope. The camera that is being drawn onto the plane has a smaller fov to make the zoom. When you move backward, you can see the cylinder, which means that it is lagging behing. Setting its inertia to 0 doesn’t help. Moving backward and switching between left and right makes the cylinder seem to zip across the plane. Any ideas or help?

Thanks, Givo

Are you doing any physic updates? It’s prolly a timing issue of where you are repositioning it, if there are phyics happening you will prolly want to do it after the physics step on the render stack

There is currently no physics engine. The scope will have physics, though, in the game.

When are you applying your update?

onBeforeRenderUpdate?

? I just have the camera (scope2) parented to the camera.

I would unparent it and just update it prior render

See if that fixes it

So, like not have it parented, but update the position to whatever before render?

https://playground.babylonjs.com/#GQCSSP#3

without looking around, it stays in sync. But how would I do the rotation?

It works if you change registerBeforeRender to:

	scene.registerBeforeRender(function () {
        renderTargetTexture.renderList.forEach((m) => m.computeWorldMatrix());
        renderTargetTexture.render();
    });

It would seem that the object world matrices are updated after registerBeforeRender is called on the scene…

1 Like

Another solution is to render the texture in registerAfterRender:

https://playground.babylonjs.com/#GQCSSP#4

That way, you’re sure the world matrices are computed and don’t need to do it yourselves (the engine may do it better than you, by not updating invisible objects, for eg).

Of course, doing it this way, your texture is one frame behind the current frame…

1 Like

Clone the rotation quat and apply it? Also check out @Evgeni_Popov solution depending on what you are doing it might work. I’m on my phone and have not looked at your scene so am not sure which is best.

Thanks for the help! Do you get my idea? and how neat it will be? Works great @Evgeni_Popov, can’t wait to integrate it.

Now where did I put that model file?

Hey @julien-moreau is something like this possible with the editor?