Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

The source code is in the page if you want to check it out (cooker/Fruit.gd) but, basically, each fruit is a Polygon2D (it doesn't need to be one but it's easier this way) and the knife has a polygon too. Then you need to clip those two polygons to get the parts with Geometry.clip_polygons_2d(fruit_polygon, knife_polygon) that will give you 2 or more polygons. After that you need to set the correct UVs for those polygons with:

        var poly = splitted_fruit.get_poly()
        poly.polygon = points
        poly.texture = Poly.texture
        var half_size = poly.texture.get_size() / 2.0
        var uvs = []
        for j in points.size():
            var vec = (points[j] + half_size)
            uvs.push_back(vec)
            
        poly.uv = uvs
Which basically moves all the UVs to the correct position in the splitted polygon.
This way you have them splitted, you can add them to a RigidBody2D and apply some forces (like I did in the game) so they fly out of the screen.

Thanks for the detailed answer! Wasn't expecting this...

Very cool!!!