www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Kumaraswamy on October 19, 2021, 09:52:27 AM

Title: Collision between two objects
Post by: Kumaraswamy on October 19, 2021, 09:52:27 AM
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?
Title: Re: Collision between two objects
Post by: EgonOlsen on October 24, 2021, 03:17:54 PM
You have to enable collisions on the object to be registered. Maybe this helps: https://www.jpct.net/wiki/index.php?title=Collision_detection (https://www.jpct.net/wiki/index.php?title=Collision_detection)