Using an invisible mesh and attaching a physics body to it is likely the best way. You’re not alone in wondering this, though-- it looks like these guys also wound up using some sort of invisible mesh for their 2D collisions
You could project the 8 vertices of the bounding box and take the min/max of x/y for a crude 2D bounding rectangle. If you need more precision and pixel perfect collision detection, then I don’t see an easy way to do that… I think the best way would still be to have your objects in 3D with correct z positionning for the regular collision system to work. If that is a problem for rendering order that the z-buffer can’t handle, maybe split some objects to dispatch each parts in different rendering …
Hi @Jieling_Yang
I did a quick test with physics and a sprite:
https://www.babylonjs-playground.com/#VGY2FA#1
I attached the sprite to the physics object using scene.registerBeforeRender.
The main issues I see are:
difficulties to tweak the physics to get the exact controls you want (friction, momentum,…)
carrefully set the collision volume
In my PG, you can change player1Mat.alpha = 0.5; to see the collision sphere (might help you later for debugging)
4 Likes