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. 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?
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 thisupdate
function is called inscene.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 inscene.onBeforeRenderObservable
, else it is when you callTrailMesh.start
. So:- if using
autoStart = true
, you must register your observer inscene.onBeforeRenderObservable
(that will callcube.computeWorldMatrix()
) before creating the trail mesh - if using
autoStart = false
, you can register your observer inscene.onBeforeRenderObservable
whenever you want, as long as it is before callingTrailMesh.start
.
- if using
I used the latter method as it is a bit more convenient:
Hey thank you kindly. That fixes it.