Box2d Collisions Made Easy

Get the latest news on new features, bug fixes and version updates right here!

Box2d Collisions Made Easy

Postby rob » Sun Mar 23, 2014 7:45 pm

Hey folks, quick update on dev branch:

http://blog.irrelon.com/box2d-collisions-made-easy/

Cheers,

Rob
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
User avatar
rob
Site Admin
 
Posts: 316
Joined: Tue Oct 22, 2013 5:08 pm

Re: Box2d Collisions Made Easy

Postby JudgeX » Tue Apr 08, 2014 12:20 am

Thank you, this is a great feature and I've already started using it.

Could you give us a quick example that demonstrates how to properly use contactData?

Also, can this be used to handle collisions with others of the same category effectively? I seem to be having issues getting them to fire for both objects this way.
JudgeX
 
Posts: 21
Joined: Mon Jan 06, 2014 7:46 am

Re: Box2d Collisions Made Easy

Postby rob » Tue Apr 08, 2014 9:45 am

Hey ya. I think contactData is generated by box 2d. It should be available in the box 2d docs.
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
User avatar
rob
Site Admin
 
Posts: 316
Joined: Tue Oct 22, 2013 5:08 pm

Re: Box2d Collisions Made Easy

Postby robaldred » Fri Apr 25, 2014 12:13 pm

Great stuff, I've been handling collisions before with relative ease using
Code: Select all
ige.box2d.contactListener(beginContactHandler,endContactHandler,preContactHandler)
but this certainly makes it much simpler.
Moving the selection and comparison of entities that have collided to the engine instead of my game code.

There are two things I've noticed what would be great.

1.
There is only collisionStart, collisionEnd
thismeans there's no way to supply a pre solver.
We'd need a collisionPreSolver event or something, pre solvers can be used to cancel the collision before it actually triggers with contact.SetEnabled(false), useful in many circumstances... For example
In my tank wars esque game I use it to stop players from being able to hit themselves with either own shells.

In this case I still have to implement the entire collision handling with box2d contactListener.

2. The entity that hit the listener is not available without extra work, you can get it using something this, but itwould be nice if this was already passed to the callback.
Code: Select all
var ea = contactData.igeEntityA()
var eb = contactData.igeEntityB()
var hit_by = null;
if(ea == @) {
  hit_by == eb;
} else {
  hit_by == ea;
}


In short all the needs changing is the _checkContact method in IgeEntityBox2d
Code: Select all
247: listener.callback(contact);
255: listener.callback(contact);

Some become... (or similar)
Code: Select all
247: listener.callback(contact,otherEntity);
255: listener.callback(contact,otherEntity);


Thanks
Rob
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
robaldred
 
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England


Return to New Features, Latest Versions & General Updates

Who is online

Users browsing this forum: No registered users and 1 guest
cron