# Trail lags 1 frame behind

**URL:** <https://forum.babylonjs.com/t/trail-lags-1-frame-behind/8856>\
**Category:** Questions\
**Created:** [February 28, 2020, 8:07am UTC](https://forum.babylonjs.com/t/trail-lags-1-frame-behind/8856 "2020-02-28T08:07:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![qbrunner](https://avatars.discourse-cdn.com/v4/letter/q/f6c823/32.png) [@qbrunner](https://forum.babylonjs.com/u/qbrunner)\
**Post date:** [February 28, 2020, 8:07am UTC](https://forum.babylonjs.com/t/trail-lags-1-frame-behind/8856/1 "2020-02-28T08:07:45Z")

</div>

I am using a trail mesh in a game, but I found that the trail lags behind one frame. I made a playground example to illustrate my point [Babylon.js Playground](https://www.babylonjs-playground.com/#ALW8PF). Just uncomment the lines in the animate function to see how the trail seperates from the mesh as it gets faster. How can I make the mesh stick to the object without having to calculate where it is in the next frame? Is this a bug and if not then what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [February 28, 2020, 8:37am UTC](https://forum.babylonjs.com/t/trail-lags-1-frame-behind/8856/2 "2020-02-28T08:37:52Z")

</div>

There are two things:

- the trail `update` function is using the generator mesh (the cube in the PG) world matrix for its computation. But because this `update` function is called in `scene.onBeforeRenderObservable`, the cube world matrix is not up to date yet: you have to call it yourself
- in autoStart mode, it is the trail constructor that is adding the call to the `update` function in `scene.onBeforeRenderObservable`, else it is when you call `TrailMesh.start`. So:
  - if using `autoStart = true`, you must register your observer in `scene.onBeforeRenderObservable` (that will call `cube.computeWorldMatrix()`) before creating the trail mesh
  - if using `autoStart = false`, you can register your observer in `scene.onBeforeRenderObservable` whenever you want, as long as it is before calling `TrailMesh.start`.

I used the latter method as it is a bit more convenient:

[https://www.babylonjs-playground.com/#ALW8PF#2](https://www.babylonjs-playground.com/#ALW8PF#2)

---

<div class="post-metadata">

**Author:** ![qbrunner](https://avatars.discourse-cdn.com/v4/letter/q/f6c823/32.png) [@qbrunner](https://forum.babylonjs.com/u/qbrunner)\
**Post date:** [February 28, 2020, 8:41am UTC](https://forum.babylonjs.com/t/trail-lags-1-frame-behind/8856/3 "2020-02-28T08:41:18Z")

</div>

Hey thank you kindly. That fixes it.
