Seeking suggestions on sprites and collision

Hi guys,

I’m preparing to create sprites with collision/gravity on them (imaging 2D characters runing around in 3D world). However it seems only meshes have proper functions for doing so.

By reading tutorial of camera collision, I think it’s doable by creating a mesh around the sprite, same to the camera ellipsoid idea. So I’m thinking something like this:
image

My questions are:

  1. Is this the correct way?
  2. If so, what possible pitfalls I should be aware?

Many thanks!

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)

1 Like

Hi Cedric,

That’s exactly what I’m planning!

It seems pretty straightforward and simple so I guess it’s the correct way to go.

Thank you so much!

1 Like