# How to sync PhysicsBody / TransformNode immediately?

**URL:** <https://forum.babylonjs.com/t/how-to-sync-physicsbody-transformnode-immediately/45937>\
**Category:** Questions\
**Tags:** physics\
**Created:** [November 26, 2023, 12:08pm UTC](https://forum.babylonjs.com/t/how-to-sync-physicsbody-transformnode-immediately/45937 "2023-11-26T12:08:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Kerr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/joe_kerr/32/39017_2.png) [@Joe\_Kerr](https://forum.babylonjs.com/u/Joe_Kerr)\
**Post date:** [November 26, 2023, 12:08pm UTC](https://forum.babylonjs.com/t/how-to-sync-physicsbody-transformnode-immediately/45937/1 "2023-11-26T12:08:02Z")

</div>

Hi everyone,

Please see here: [https://playground.babylonjs.com/#Z8HTUN#786](https://playground.babylonjs.com/#Z8HTUN#786)

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  
Joe

---

<div class="post-metadata">

**Author:** ![Aus\_Karlos](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@Aus\_Karlos](https://forum.babylonjs.com/u/Aus_Karlos)\
**Post date:** [November 26, 2023, 1:22pm UTC](https://forum.babylonjs.com/t/how-to-sync-physicsbody-transformnode-immediately/45937/2 "2023-11-26T13:22:07Z")

</div>

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

```auto
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();
        }
])

```
