# Vector3 project with current camera (avoid 1 frame delay)

**URL:** <https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790>\
**Category:** Questions\
**Created:** [April 7, 2020, 7:47am UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790 "2020-04-07T07:47:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![earthendev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/earthendev/32/34897_2.png) [@earthendev](https://forum.babylonjs.com/u/earthendev)\
**Post date:** [April 7, 2020, 7:47am UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790/1 "2020-04-07T07:47:36Z")

</div>

I have some custom panning/zooming logic in my project, so I can’t use attachControl on the camera for panning. I still need the GUI moveToVector3 method though, which is internally based on Vector3.Project:

> <https://github.com/BabylonJS/Babylon.js/blob/fa60299c4d2cf3a0554c770cbd60734a8cee3f2f/gui/src/2D/controls/control.ts#L1077>

It works fine actually, but there is always a lag of one frame. First of all I had to do some contortions to get it work after loading (on the first frame) and also my GUI lags behind a little (just 1 frame, so it’s not that bad but still I’d like to avoid it).

I tried doing it with TransformNodes and linkWithMesh, but that was very glitchy (I generate linkOffsets on the fly, and they were randomly ignored), although a little smoother when it worked. I can make a PG on request, but it might take a while. From a cursory look at the source code, I can’t quite understand how linkWithMesh avoids the 1 frame lag or why there would be glitches.

Is there any other way to remove the 1 frame delay? TransformNodes are rather messy for my use case anyway.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 7, 2020, 3:39pm UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790/2 "2020-04-07T15:39:51Z")

</div>

When do you call the moveToVector3? To avoid any lag, you can do it on the scene.onAfterRenderObservable

---

<div class="post-metadata">

**Author:** ![earthendev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/earthendev/32/34897_2.png) [@earthendev](https://forum.babylonjs.com/u/earthendev)\
**Post date:** [April 7, 2020, 3:42pm UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790/3 "2020-04-07T15:42:40Z")

</div>

I’ll try. Could make a difference. Currently I am doing it in a onDragObservable callback.

---

<div class="post-metadata">

**Author:** ![Ontropy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ontropy/32/24424_2.png) [@Ontropy](https://forum.babylonjs.com/u/Ontropy)\
**Post date:** [April 30, 2022, 12:59am UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790/4 "2022-04-30T00:59:20Z")

</div>

Did it work? Were you able to find a solution/alternative? onAfterRenderObservable did not solve it for me ☹

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 2, 2022, 2:49pm UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790/5 "2022-05-02T14:49:51Z")

</div>

would be great to share a repro in the Playground so that @PolygonalSun might have a look ?

---

<div class="post-metadata">

**Author:** ![Ontropy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ontropy/32/24424_2.png) [@Ontropy](https://forum.babylonjs.com/u/Ontropy)\
**Post date:** [May 3, 2022, 3:19am UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790/6 "2022-05-03T03:19:24Z")

</div>

Apologies for bumping this up. But after further trial and error I was able to fix it using onBeforeRenderObservable.

---

<div class="post-metadata">

**Author:** ![kloklike](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@kloklike](https://forum.babylonjs.com/u/kloklike)\
**Post date:** [April 28, 2023, 10:09pm UTC](https://forum.babylonjs.com/t/vector3-project-with-current-camera-avoid-1-frame-delay/9790/7 "2023-04-28T22:09:34Z")

</div>

For anyone who finds this when dealing with a 1-frame delay on screen space projection, it’s possible Ontropy meant to say onBeforeCameraRenderObservable in the previous message. If you don’t want to rearrange your code into a different callback function, another way to remove the 1 frame delay is by calling scene.updateTransformMatrix() before doing your Vector3.Project
