Static rigid colliding shapes

Hi All!
I’m trying to get two models of the same geometry to collide without Raycasting. Is this possible?
I instantiate the two objects with StaticModel, RigidBody, and ColllisionShape and each has mass of ‘1’.

Lord Fiction

Does your Scene have a PhysicsWorld?

1 Like

Did you use SetTriangleMesh() for the CollisionShape?

I may be completely wrong, but I think you have to use one of these: SetBox(), SetSphere(), SetStaticPlane(), SetCylinder(), SetCapsule() or SetCone() if the objects have mass.

SetTriangleMesh() only worked here for static objects (had no mass).

EDIT: This worked here for me:

for (unsigned i = 0; i < 3; ++i) {
    Node *node_ = scene_->CreateChild("cube");
    node_->SetPosition(Vector3(0.0f, i+5.0f, 0.0f));
    node_->SetScale(Vector3(0.5f, 0.5f, 0.5f));

    StaticModel *staticModel_ = node_->CreateComponent<StaticModel>();
    staticModel_->SetModel(cache_->GetResource<Model>("Models/cube.mdl"));

    RigidBody *rigidBody_ = node_->CreateComponent<RigidBody>();
    rigidBody_->SetMass(1.0f);

    CollisionShape *collisionShape_ = node_->CreateComponent<CollisionShape>();
    //collisionShape_->SetTriangleMesh(staticModel_->GetModel(), 0); // This didn't work here.
    collisionShape_->SetBox( Vector3(2.0f, 2.0f, 2.0f) ); // This worked here.
}
1 Like