[SOLVED] Strategy for Fruit Slicer-Like Swipe Detection

I’m currently prototyping a fruit-slicer-like game.
I’m only planning to integrate a simple hit / no-hit mechanic (no direction of cut / custom cut).
What would be a simple strategy to detect this “swipe over / through” on 3d-Objects ?
I can remember an old babylon.js example, where an actual line was created and then checked for collision, but maybe there is a simpler way.

As always, thanks for your help.

Hi @Rechi,

So, if you don’t want to go all the way creating custom line meshes you can use a raycast.

If the game is taking place on the XY plane, then convert your touch input in world points at the same Z distance from the camera as the fruit objects and do a raycast from start to end, or for better accuracy multiple ones that follow the touch gesture.

You can check that way if there was a hit with an object.

1 Like

Thanks Leonidas, that makes sense.
Just out of curiosity - If I would create a custom line mesh, how would I then detect the collision, some Frame Buffer Magic?

So if you’ve built a custom mesh, each line segment could be potentially a separate mesh instance and instead of raycasts, you could use the bounding box for checking intersections.

I am not saying that’s better, I think I would still use raycasts in that case as well.

Assuming 2D, you could do a simple line to circle/box intersection check which would be cheaper and not need the Ammo physics system.

2 Likes

It’s also easy to setup pc.BoundingBox instances for your fruit objects and use their raycast method, to fully avoid using Ammo.

1 Like

Thanks guys.
The 2d version also makes a lot of sense (reminds me of my old flash-stuff).
I will check If I need Ammo for the basic-gameplay, and then will see which of your workflows works best for me. Thanks again for your time!

1 Like