How to make Rock Debris

Hey guys, I been trying to do this but still unable to make it work until now. i have rock coming from different directions, once they hit the floor, it will break into 3 pieces and bounce up in the air and drop to the ground. Anyone have any idea to do it?

1 Like

No idea how are you moving the rocks, so assuming you know what you’ve to do with each debris, the idea is to use a repeat loop with a random angle:

Conditions: Rock collides with Floor Repeat 3 times Conditions: No conditions Actions: Create object Debris at Rock.X() ; Rock.Y() Do = RandomInRange(-45, - 135) to the angle of Debris Make Debris to move in Debris.Angle() direction

If the angle is not random, for example debris always bounce with angles -105 -90 and -75 and you don’t want to make it complex with indeices variables and so, you can just copy the same code three times in different sub-events:

[code]Conditions: Rock collides with Floor
Actions: No actions

// sub-event
Conditions: No conditions
Actions: Create object Debris at Rock.X() ; Rock.Y()
         Do = -105 to the angle of Debris
         Make Debris to move in Debris.Angle() direction

// sub-event
Conditions: No conditions
Actions: Create object Debris at Rock.X() ; Rock.Y()
         Do = -90 to the angle of Debris
         Make Debris to move in Debris.Angle() direction

// sub-event
Conditions: No conditions
Actions: Create object Debris at Rock.X() ; Rock.Y()
         Do = -75 to the angle of Debris
         Make Debris to move in Debris.Angle() direction[/code]

After creating the debris, you can delete the original rock.

Thank you for your reply again Lizard-13, no, I get how to do the random debris angle. The problem mainly lies with how do it bounce those debris up in the air and drop to the ground so it can hit the player. I am thinking of parabolic equations, but is there any simpler way to do that?

You can use the Physics behavior, or do the projectile movement yourself.

Projectile movement is not hard at all, you have a horizontal speed (speedX), a vertical speed (speedY) and gravity, each debris has an initial speedX (negative, positive or 0) an an initial speedY (negative), they are object variables:

Variable speedX = 50 Variable speedY = -200
In each frame update the vertical speed using the gravity and move the object using the speeds, with a gravity = 150 it would be:

Variable speedY + 150*TimeDelta() Position X + speedX*TimeDelta() Position Y + speedY*TimeDelta()

Hope that help :slight_smile:

Nice! Thanks Lizard-13 again for your help :slight_smile: i will try on this later :smiley: