Collision between two objects

Started by Kumaraswamy, October 19, 2021, 09:52:27 AM

Previous topic - Next topic

Kumaraswamy

I am new to 3d models and handling them, I want to know if there are any examples to detect collision between two objects?  :)

So far I have tried

First model:


object3D.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS | Object3D.COLLISION_CHECK_SELF);
        object3D.addCollisionListener(new CollisionListener() {
            @Override
            public void collision(CollisionEvent collisionEvent) {
                Log.d("Renderer", "collision: " + collisionEvent);
            }

            @Override
            public boolean requiresPolygonIDs() {
                return false;
            }
        });


And


((MyModel) mymodel).getObject3D().setCollisionMode(Object3D.COLLISION_CHECK_OTHERS | Object3D.COLLISION_CHECK_SELF);
        ((MyModel) mymodel).getObject3D().addCollisionListener(new CollisionListener() {
            @Override
            public void collision(CollisionEvent collisionEvent) {
                Log.d("Model3d", "collision: " + collisionEvent);
            }

            @Override
            public boolean requiresPolygonIDs() {
                return false;
            }
        });
        SimpleVector vector = new SimpleVector();
        vector.y = 10;
        ((MyModel) mymodel).getObject3D().checkForCollision(vector, 100);


So far, the event is not triggered  :-\
Am I missing something?

How do I listen to collisions?

EgonOlsen

You have to enable collisions on the object to be registered. Maybe this helps: https://www.jpct.net/wiki/index.php?title=Collision_detection