saharan / OimoPhysics

A cross-platform 3D physics engine
MIT License
863 stars 68 forks source link

events? #2

Closed koblongata closed 7 years ago

koblongata commented 11 years ago

Hello,

I was wondering what kind of events i can use when collision is detected? I have looked through the code but couldn't find one that I can use, maybe I have overlooked something? I need some sort of collision event notification to make a game out of it.

By the way, It's a wonderful library Thank You :)

saharan commented 11 years ago

Hello,

Sorry, collision events are not implemented yet. But you can detect collision between shapes. For example, this is a method to check whether shapes are colliding or not:

public function isCollided(shape1:Shape, shape2:Shape):Boolean {
    var contacts:Vector.<Contact>;
    var numContacts:uint;
    if (shape1.numContacts < shape2.numContacts) {
        contacts = shape1.contacts;
        numContacts = shape1.numContacts;
    } else {
        contacts = shape2.contacts;
        numContacts = shape2.numContacts;
    }
    for (var i:int = 0; i < numContacts; i++) {
        var contact:Contact = contacts[i];
        if (contact.shape1 == shape1 && contact.shape2 == shape2 ||
            contact.shape2 == shape1 && contact.shape1 == shape2) {
            return true;
        }
    }
    return false;
}

Thanks.