Can you modify the hit mask from JavaScript

I’ve been thinking about the games where you swipe the screen and slice an object into pieces. I was wondering if it would be possible to modify the hit box of a physics object using JavaScript. It would just be a simple rectangular or polygonal shape.

My concept is to create a duplicate object. Mask opposite sections on each object and then using the physics behavior, let them fall apart.

I can figure out the masking.

If that’s not possible or practical, my backup idea would be use the same concept but stick the divided sprites to hidden objects that would slide apart. It would be simple enough to align to rectangles along the cut line.

It doesn’t need to look real. This is currently just a challenge to see if I can do it.

IMG_20231018_032546
anyone have any better ideas?

I am known for Frankenstine like solutions
And i have one here for you

1st of all slice angle would not need to be AS MUCH precise as you think
For most if not all users slices that are horizontal or vertical or diagonal would be enough kinda like


So basically you have only 4 ways to slice your object
And now tricky part would be to register from which edge slice starts and on which ends to do that kind of slice
Which i have no idea how to od with physics objects but i guess it is doable

Where my idea on how to deal slice itself would be
You do not slice your object you simply create 2 objects which are just 2 parts of original object (depending on slice angle) and delete original object

And you just faked slicing an object

Like i said Frankenstine solution but for end users it would look like they are actually slicing something

1 Like

Thanks. I need to play around. I figure that I can use the swipe behavior for the angle.

The mask would be a shape painter. The corner points can come from the bounding box and the other points either from a formula or using a ray cast from each end point.

I’m wondering if it would be easier to just add a force to make the slice move in the direction of the slice and then a force to make it fall.

There’d be no need for actual collisions. I also considered the Marching Squares behavior.

My god i totally forgot about marching squares which would be useful here

Anyway depending on slice angle you could just prepare RandomInRange force applied to both pieces

For example for horizontal slice you could go with top part RandomInRange(-100,-80) or even bigger range
And it would give enough RANDOM feel to each piece to fool players into it looking natural

On top of that rotation for each piece in direction it would make sense with RandomInRange speed

1 Like