Objects slashing physics like in the Fruit ninja, but in VR

Hi, it’s a question where I look for a way to reproduce similar physical behavior like in slashers (Fruit Ninja, for example). I see this by dividing the functionality onto next list:

  1. Controlling VR controllers like swords/katanas and getting event of slashing object (fruits) with them
  2. Slicing object (fruit) on 2 parts with their next logic of flying away from the slash move with gravity

If you have exact features - please, tell me what I should look at. If your have docs about wht I’m looking for - share it with me pls. And if you have examples - it would the best option

Thank you

Hey there!

Here a couple relevant doc pages for your project. They should be good starting points for figuring out what features you want to use:

Setting up hand tracking and using our default hand mesh and rig

Setting up input controllers and getting their position

Attaching the sword model to a hand bone

Assigning sword and fruits with physics bodies to enable collision detection

Detecting collisions between physics bodies

Using CSG2 for splitting a fruit mesh into two

Or, playing with NGE to split a fruit mesh into two

And, just in case, here’s some WebXR demos.

Checking the “depth” of the slash on a fruit-- rather than just if the slash happened-- will be a fun engineering question. Do you need the path of the slash on the fruit? Or could you instead time the contact between the sword and the fruit?

I just found this post in the wild, and it reminded me of this thread. It has a demo for slicing meshes in half using CSG.

I did fruit ninja slices in this, the visual for it at least. This could easily be transitioned to a VR setup.

For experiments I created a line of cubes and a pen, that moves from side to side on a mouse clicking. But for now, cuz both a cube and a pen have a mass, they don’t intersect but collide and move away outta each other. And if I set a mass of any of it as 0, then this object won’t move on applyForce or applyImpulse. Even if to set a mass as 0, objects will collide, but not intersect. What to do in this case?

BTW, I didn’t find any other method to move an object with a constant velocity, is there such methods?

Hello :slight_smile:

Maybe it’s not the best way, but here is the way I would go :

  • Manually move your cubes as pure meshes, with no physics (since you want to choose their exact position, no need for physics for the moment)
  • On collision with the saber, instanciate 2 halfs of your cube, and dispose the original one
  • Set physics on the 2 parts, and impulse them to each direction

I was gaving a try to your this for fun, and lines after lines I ended up coding the whole stuff :joy: (no VR) Enjoy !

Screencast from 19-12-2024 15:15:26

7 Likes

great !!!

Epic :smile:

Great work!

With random meshes and CSG2 x)

It will sometimes fail when the cut yields mesh with 0 vertices (at the very edge). A fix for another day.

2 Likes