-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ghost Objects/Triggers #82
Comments
At the moment there is not. I don't know if Ammo.js includes this functionality from Bullet Physics, but the starting point would be to locate it in Ammo.js. |
This would indeed be quite a useful feature. Apparently in bullet physics the only thing you change are the collision flags: http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers#Trigger I'm not quite sure how Ammo.js works but this might be the relevant part of the code: |
I haven't had good luck with the callbacks or collision flags with Ammo. It's somewhat probable I'm just not doing it right; unless someone else figures those out, ghost objects will be included starting in version 2 |
Until this gets implemented, here's the workaround I've been using in case anybody is interested. After you've created a new mesh (but before you add it to the scene) just manually set the collision flags: myPhysijsMesh._physijs.collision_flags = 4; where myPhysijsMesh is your mesh. 4 (0b100) is the bullet collision flag CF_NO_CONTACT_RESPONSE; ideally it would be some kind of constant in Physijs or something. Your mesh then acts as a trigger meaning this: myPhysijsMesh.addEventListener('collision', function(other_object, relative_velocity, relative_rotation) {
}); would run just one time when the object enters (or re-enters) the space inside your mesh but travels through it like air. There might be a flag for continuous triggering while it's still inside. The reason this works is because adding an object to your scene runs this in the web worker: body = new Ammo.btRigidBody( rbInfo );
if ( typeof description.collision_flags !== 'undefined' ) {
body.setCollisionFlags( description.collision_flags );
}
world.addRigidBody( body ); and _myPhysijsMesh.physijs ends up becoming description. I checked the ammo.js source code and sure enough there's also a getCollisionFlags which would allow the normal bit setting when you change the collision flags (i.e. setCollisionFlags(getCollisionFlags() | 4)). I'm not sure how difficult it would be to add collision flag getters and setters to the Physijs.Mesh prototype (or even if they can be changed on the fly like that; not sure what happens to body once it's added to the world) or if it would make more sense to pass them as a parameter like mass. Either way if I figure it out before anybody else I'll be sure to request a pull or something. |
@chandlerprall Did you find any way of using triggers and callbacks yet? I've been experimenting a bit with the callbacks, I can make Ammo execute my callback, but then I can't get the participating collision objects :( |
@schteppe I never had any luck with Ammo's callbacks |
@chandlerprall :( Do you know if there is any other way of implementing working triggers/sensor objects then? |
I haven't looked into it for at least a year. It's very possible one of the recent Ammo builds enabled these. |
Ok, thanks! Will let you know if I succeed with this. |
@schteppe take a look at the code in this PR which adds a callback https://github.com/chandlerprall/Physijs/pull/150/files |
Inspired by issue chandlerprall#82
I'm wondering if there is anyway through physijs if it's possible to add Collision event listeners that only register that a collision has happened, and not apply an impulse? If not, any ideas on where I should look in the source to add that?
The text was updated successfully, but these errors were encountered: