# Thread: is it possible to dynamically slice objects like in fruit ninja?

1. ## is it possible to dynamically slice objects like in fruit ninja?

I want to create this game mechanic and have tried searching all over the place and I can't find anything good, isn't there a shader that can hide part of an object or something? so then you can just duplicate the object, hide the top and hide the bottom separately so it gives the illusion of slicing the object

2. bump

cause i rly need some help on this lol

3. cut.mfa

voici une des façons

4. That's cool but what i'm looking for is to be able to cut from any angle

5. avec un actif je ne pense pas que ce soit possible ou alors avec un code tres compliqué, peut etre avec objet surface mais tout depend de l'utilisation finale

6. il faut que tu expliques plus en detail (un seul actif a l'ecran? y a t il un fond ou juste une couleur d fond?)

7. Basically imagine an object, I want to be able to cut it in half or diagonally like in fruit ninja, there will be a background, I can try the surface object but I cant do it diagonally then

8. avec un actif tu peux le decouper suivant la methode que je t'ai montré avec eventuellement plusieurs angle prédéfini mais je pense que c'est tout ce qui est possible de faire

9. That's what I thought I should do, thanks though!

10. Someone referred me this problem through Discord, and is doable when using some vector maths.

The shader consists of a single dot product between position (offset by a given value) and the direction (normalised). Any pixels resulting with a negative value have their alpha value set to 0.

To work with this shader:
- you need an Offset (which is position from the top left of the displayed sprite),
- you need to give an angle in X, Y form. If you already have angle in degrees, doing fAngleX = cos(angle), fAngleY = 0 - sin(angle) should do. This should be perpendicular to the actual cutting angle.

Here is an example (from the two screenshots above), it includes two frames, the latter dealing with an issue if the cutting object is rotating: CutByAngle.zip

If you'd want to get the other cut side, negate the cos(angle) and 0 - sin(angle) parts. You should be able to set the effect parameters once and have it work well. (Setting effect properties and cos/sin are really expensive!)
If any terms here were confusing, googling them along with "vector maths" or "trigonometry" should help, hope this helps!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•