Physics Imposter (cannon.js) - worldPoint.vsub is not function when using applyForce or applyImpulse

Hi,

I am trying to detect collision between imported glb object model and box, I have tried with intersectMesh using boundingBox info but it is not working perfectly for car model specially bonnet and trunk areas, I am expecting the collision to be occurred when hitting body of the glb object. So I am using one of available physics engine “cannon” feature physicsImposter.

but while applying Force its giving error Uncaught TypeError: worldPoint.vsub is not a function
tried with Implulse also but same error.

if (pointerRef.current && pointerRef.current.length() > 0) {
const newPosition = eventData.pickInfo?.pickedPoint || new Vector3();
const movementVector = newPosition.subtract(pointerRef.current);

      // Apply the movement vector as force to the box's physics impostor
      boxBodyRef.current.applyForce(movementVector.scale(50), draggedMeshRef.getAbsolutePosition());

      pointerRef.current = newPosition;
    }

below is module versions I am using
@babylonjs/core”: “4.2.1”,
@babylonjs/gui”: “4.2.1”,
@babylonjs/loaders”: “4.2.1”,
“cannon”: “^0.6.2”,
“react-babylonjs”: “3.0.31”,

Vsub is a function on cannon’s side, it’s going to be hard to know what is going on there. Have you checked the values you’re passing to the function?

but it is not working perfectly for car model specially bonnet and trunk areas, I am expecting the collision to be occurred when hitting body of the glb object

This is in line with the way bounding box works, because the bounding box is, well, just a box enclosing the entire mesh. But if you can separate the mesh with parts, with each one having its own bounding box, then the collisions will be more precise :slight_smile: That’s usually how games do collisions.

image

1 Like