Move static physics body with associated mesh

I’m trying to use raycasts to detect hits on certain meshes.
When none of the meshes moves, this works fine. However, in my project some of the meshes move around (they’re all simple box meshes). When I create a static physics body for one of these meshes, I want to update the body’s position to the mesh’s position each frame, so raycasts can hit it (rotations or billboarding is not required).
Using a dynamic or animated body makes moving the associated mesh no longer possible when setting it’s position.

See PG: https://playground.babylonjs.com/#PY59V9#23 - the physics body is not following the mesh.

Is it possible to simply move a body to a world position?
I’m using the havok plugin, by the way.

cc @Cedric

body.disablePreStep = false

the prestep will sync the body with the mesh but is more computationally expensive.

2 Likes

Thanks, that does the trick!
Just to check, more computationally expensive than what exactly?
And there’s no way to just force-set the body to a certain world position which would be cheaper to do? In my case, I’m just using the meshes to check if a ray can hit it, not using collisions or other physics.

@Pryme8 probably means “more computationally expensive than disablePrestep = true”

Related posts:

Also note the response in the last link:

2 Likes

Thanks for the extra info HiGreg!
I’ll use your way of managing the preset step in my project :slight_smile:

1 Like

Note the code change on the edit I just made to the code in the third link.

1 Like

Thanks for letting me know, I’ve updated my project with your edit :+1: