How to sync PhysicsBody / TransformNode immediately?

Hi everyone,

Please see here:

It seems, when syncing, the physics position takes 1 frame to catch up with the actual mesh position. In consequence the physics raycast misses.

You can fix this by waiting a frame before you shoot the ray. But say you shoot lots of physics raycasts in your code and that code is never async…

I tried havok.syncTransform but while it makes the ray hit, it voids the position update. (guess its syncing the other direction)

Best wishes

Depending on how you wanted to initiate the raycast you could set it up inside registerBeforeRender.

scene.registerBeforeRender(() => {
        const physicsEngine = scene.getPhysicsEngine();
        var raycastResult = new BABYLON.PhysicsRaycastResult();
        var start = camera.position.clone();
        var end = sphere.position.clone();
        physicsEngine.raycastToRef(start, end, raycastResult); 

        if(raycastResult.hasHit) {
            scene.clearColor = BABYLON.Color3.Green();
        else {
            scene.clearColor = BABYLON.Color3.Red();
1 Like