Unable to rotate an mesh when PhysicsAggregate is aplied

I have imported a mesh from a babylon repository, but when I try to rotate over the Y axis, it simply doesn’t work. I’ve looked up the docs but can’t find anything significant.

      const result = await SceneLoader.ImportMeshAsync("", "https://assets.babylonjs.com/meshes/", "HVGirl.glb", scene);
      const player = result.meshes[0];
      player.position.y = 2;

      const shapeCapsule = new PhysicsShapeCapsule(
          new Vector3(0, 2, 0),
          new Vector3(0,  0.35, 0),

      const aggregate = new PhysicsAggregate(player, shapeCapsule, { mass: 1, restitution: 0 }, scene);
      aggregate.body.disablePreStep = false;

      player.rotation.y = Math.PI / 3 // not working

Bonus question:
I was unable to do PhysicsAggregate(player, PhysicsShapeType.CONVEX_HULL... its complaining. Is it because I’m targeting a root node and not the children?

Welcome! :slight_smile:

So far I find out, you should first set the position of the mesh then create the aggregate. If you need to move the mesh later again, you have to dispose and recreate the aggregate after movement.

it’s about rotation, not position.
I copied the wrong code sorry

Did you try to set this property to false?

yes, you can see in the code above, right below const aggregate ...

I think result.meshes[0] might be the parent transform of the mesh you are interested in. You should check for result.meshes[1]
Please provide a PG so we can more easily test.

Many things going wrong:

  • There is no physics initialization
  • no BABYLON namespace use
  • no plane ground (physics body will fall through)
  • use quaternion over euler

Once fixed it looks like this:



Can you explain why setting the roration Y value directly is not working after applying physics to a mesh?
What is the difference between .rotation and .rotationQuaternion?

Here is some related documentation : Rotation Conventions | Babylon.js Documentation
Rotation Quaternions | Babylon.js Documentation

Basically, there are 2 ways to set orientation: with Euler angles or quaternion. Quaternion has priority over Euler.

1 Like

I still find it hard to understand.
Does it mean that the physics engine uses the .rotation setter so I have to overwrite it with quaternions?

also, why I can’t do this:

  const aggregate2 = new PhysicsAggregate(player, PhysicsShapeType.CONVEX_HULL, { mass: 1}, scene);

Is it because player is a root node? if so, how can I group all the children into a single shape and apply physics to it?

Physics uses quaternion. so once an object is physicalized, you’ll have to use the quaternion instead of Euler rotation.
You can create the Aggregate that way but you’ll have to specify a mesh used to compute the convex_hull with. So it would look like:

const aggregate2 = new PhysicsAggregate(transform, PhysicsShapeType.CONVEX_HULL, { mass: 1, mesh: meshProxyForTheHierarchy}, scene);
1 Like