Ammo-added Collision Size determination Logic?

Hello, I’m try to change size of the collision object via AMMO code. but I can’t find way to do so.

https://playcanvas.com/project/1025434/overview/ammocollisiontest

this is my project that I’m trying to do, to add a collision to a object but using Ammo, for experimental purpose.

So I somehow managed to add collision to location of the box, but its size is being issue.(I think) The collision is there, I can detect it by raycast when shooting ray on center of the box. But it’s so tiny that I cannot stand on it, or detect the collision smoothly.

What do you think the problem is? I tried changing halfextents, localScale of RigidBody. But nothing seems to work.

var CubeColTest = pc.createScript('cubeColTest');

// initialize code called once per entity
CubeColTest.prototype.initialize = function() {
    var dynamicsWorld = this.app.systems.rigidbody.dynamicsWorld; 
    var ammoHalfExtents =  new Ammo.btVector3();
    ammoHalfExtents.setValue(2,2,2);
    const shape = new Ammo.btBoxShape(ammoHalfExtents);

    const rbodyconsinfo = new Ammo.btRigidBodyConstructionInfo (0, Ammo.btDefaultMotionState(),shape);

    const newTrans = new Ammo.btVector3 ();
    newTrans.setX(this.entity.getLocalPosition().x);
    newTrans.setY(this.entity.getLocalPosition().y);
    newTrans.setZ(this.entity.getLocalPosition().z);


    const transformDoIt = new Ammo.btTransform();
    transformDoIt.setOrigin(newTrans);


    const rbody = new Ammo.btRigidBody (rbodyconsinfo);
    rbody.setWorldTransform (transformDoIt);
    // console.log(shape.btBoxShape());
    rbody.setCollisionShape (shape);

    dynamicsWorld.addRigidBody(rbody);
};

// update cod

Hi @Deanies,

I’m not sure about your code, but one thing I’d try is to visualize the collision shape to see if that helps pinpoint the error.

There are some user made extensions like the following that can help with that: Ammo Debug Draw

Thx for your reply. I knew about this because you thankfully told me about this last time but I didn’t know how to use it. Now I figured out how to use this, I tried to see what’s going on.

but this seems like I need to find my way differently,

Though There is apparently something here(I can collide into it), Debugger shows nothing. I think it needs another solution.

image

And if I use raycast on Ammo added collisions, console reads some thing like this. entity is not defined in here,but returns normal and point somehow. Do you know why this is happening by any chance?

Your rigidbody construction info signature is not correct:

  • the motion state requires a transform, and also a new keyword, since it needs an instance
  • it also needs an initial inertia, which can be a zero vector
const inertia = new Ammo.btVector3(0, 0, 0);
new Ammo.btRigidBodyConstructionInfo(0, new Ammo.btDefaultMotionState(transform), boxshape, inertia);

Also, your transform is missing an orientation. It should be something like:

const r = entity.getRotation();
const aq = new Ammo.btQuaternion();
aq.setValue(r.x, r.y, r.z, r.w);
transform.setRotation(aq);
4 Likes

Wow Thx!!! This was the solution I wanted!! Thank you very much!

1 Like