I created a new demo. Download it, add your own (free) PBE swc file from Pushbuttonengine.com, and test the demo!
PHYSICS AND COLLISION
Box2D does many things well. While we typically want the system to manage physics, we can also use it ONLY for collision detection, then manage the consequences of the collisions ourselves. This collision detection is fast and full of good information about the collision (compared to Flash’s MovieClip.hitTest() ).
In general, when Box2D is setup and 2 (or more) objects have collisionType and collidesWithTypes properly, they react with physics – bouncing off each other, or something similar. You can also listen to the events;
If you DON’T set those properly there will be no physics (good for my needs) but you also do not get collision events (bad for my needs).
COLLISION WITHOUT PHYSICS
To get the benefits of collision detection without physics we need to use the isSensor property in Box2D. That treats the objects as sensors (detect but do not react). Then you can create a custom reaction (using 100% of Box2D’s functionality – torques/forces/etc…). PBE does not expose (at least not in a way I could fine) the isSensor property so I created a few custom classes to help.
USES OF COLLISION WITHOUT PHYSICS
* #1 You could handle your own hit detection in a game this way.
* #2 The small idea expressed in the demo, could also be used to steer computer AI around a complex race-track. Perhaps the tiles shown in the demo would be invisible to the user in a real game, and only ‘seen’ by the cars as they detect the desired angle to move around a track. This could also be used for ‘water flowing’ or ‘wind blowing’ on objects too.
ALSO FEATURED IN THE DEMO
* a) You will also see in the attached demo a Box2d setup done with XML. Nice! An even simple demo of just this part can be seen here too. viewtopic.php?f=15&t=2172
* b) You will also see Box2D objects skinned with symbols from an embedded swf. Nice! (Also shown in ‘a’ above)
* c) You will also see a component to have a Box2D object ‘face’ (in the direction of) the way its moving
- Follow comments and add your own comments on the PushButtonEngine Forums.
- Question – Anyone who wants to make many more tiles in my demo to show a more complete demo of #2 above, go for it! I’d love to see that.
[private_Free member]Enjoy this members-only content!
- Download the PBEBox2DCarAndTrack.zip Flash Builder 4.5 as3-only Project.