I’ve been working with PlayCanvas for a while now, and I’m working on a game with a lot of physics. I’m getting to grips with the ammo.js API, which I’m not very familiar with.
Currently, I’m using the convexSweepTest() function, and I can retrieve the position and normal of the hit, but not the hit object itself.
Is it possible to retrieve the entity hit by a sphere or a capsule cast? Is there another function available?
The engine will attach the entity to a body it creates, so if the body was created by the engine, you can cast it to Ammo body and you will have access to it. For example:
if (resultCallback.hasHit()) {
const body = Ammo.castObject(resultCallback.get_m_hitCollisionObject(), Ammo.btRigidBody);
// body.entity
}
With a callback like ClosestRayResultCallback or AllHitsRayResultCallback, yes, it’s possible to retrieve the hit object. But with a callback like ClosestConvexResultCallback, there’s a pointer to the hit object const btCollisionObject* m_hitCollisionObject; but I can’t retrieve the entity from this variable.
After checking with console.log(), the variable m_hitCollisionObject is not defined. It seems that it’s not possible to retrieve the hit object with convexSweepTest(). I’m going to perform a raycast with the retrieved information, such as the hitPoint and hitNormal.
However, I imported the Ammo library via the editor, and apparently, it’s not quite the same since it doesn’t contain Ammo.ClosestConvexResultCallback.get_m_hitCollisionObject().
Is it normal for the editor to import an “older” version?