Extend hitbox above a mesh?


I have reproduced my problem here!

Tower Rotate, fixed | Babylon.js Playground (babylonjs.com)

So, in my playground link, I have a checkerboard grid. The grid cells all have their own physics box. What I want to do is to listen for collision events above the checkerboard cells.

Basically the bullets are shooting over top of the gridcells, and I’d like to have an event fire off when it intersects a new cell. Is there a method I could use to elevate the physicsImposter?

If the phsyicsImposter weren’t actually attached to the object, this could work.

Edit: minor rewrite for clarity

cc @Cedric who might know ?

1 Like

Just make a grid of invisible imposters above the board?

1 Like


Wow, I thought imposters had to be attached to a mesh! I will look into this :slight_smile:

That’s probably true.

I might just run an AABB collision test for this though.

I’m not sure to understand. do you want to know on which grid cell a bullet is?

Hi Cedric, that’s exactly right. I have a checkered grid on the floor, but bullet fly through the air above the grid. I was trying to find a way to have the grid cells have an effect and light up when bullet cells fly over them.

I thought if I could put the physicsImposter for the cells above the grid, that this would work. Now I’m leaning towards making a 1:1 invisible grid above the floor, and using filterEvents instead (so that way the bullets won’t bounce off or be stopped by the physics imposters).

IMHO, it’s overkill.
if you have cells of 1x1 units, the cell number is the Math.trunc(bulletPosition).
if the cell is 2x2, then the cell number is Math.trunc(bulletPosition/2)

Alright, done!

I ended up just making two grids, and then I check for mesh intersections in the registerForFrame action. It works like a charm.

Using intersect mesh for collision detection | Babylon.js Playground (babylonjs.com)

It would be lovely though if you could pass in an array to obj.intersectsMesh(obj2). Then you wouldn’t need to iterate using a forLoop like I am doing here

Anyway, on to the next stumbling block!

Thanks for the feedback and the awesome idea @withADoveInOneHand