Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Fruit Ninja (cut the fruit) demo

IgnatzIgnatz Mod
in Code Sharing Posts: 5,396

I thought it would be fun to try slicing objects with my finger, like Fruit Ninja. The video below shows the result, and I wrote a post here, with code, which I hope some of you find interesting.

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,782

    Very neat tutorial. The effect is a lot tricker than it seems.

    In Fruit Ninja which cuts 3D shapes, it looks like they have a predefined cut path. They simply orient the 3D shape to align with the direction of the slice, and then split it. (Not sure if it still does that or if they've improved it to actually slice arbitrary pieces.)

  • IgnatzIgnatz Mod
    edited December 2015 Posts: 5,396

    I think Fruit Ninja has a set cut pattern because they have pseudo-3D animations of the cut fruit tumbling, and that would be too difficult if you cut the fruit anywhere. Also, cutting the fruit in the center every time makes it clearer to the player that it has been cut, whereas if I shave a little sliver off, you can't always be sure you cut it.

  • Posts: 154

    @Ignatz, very well done!
    I envy your patience to write everything up and explain. That part seems to be a lot more challenging than the problem itself.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Actually, I enjoy writing stuff up after I learn about it. I don't know why. :p

  • Posts: 911

    @Ignatz - nice write up. I used a similar approach:
    https://gist.github.com/Westenburg/e7c9ebc7a52b11fe283a

    I also put in a check to make the two halves fly off at angles perpendicular to the slice.

    Next step I took was to move to a polygon from a rectangle: http://codea.io/talk/discussion/6685/small-demo-chopping-up-polygons

    I felt my code was a bit clumsy and slow with multiple objects but I think I got the basics.

Sign In or Register to comment.