I’d like to share a cool trick I found, on how to make a rolling ball.
At first I thought I’d make it so it decreases the X Velocity and the Y Velocity as it rolls but that causes the ball to roll in straight lines when it starts to slow down. Anyways here’s how (link to the project at the bottom.)
First thing first, you’ll need these variables for the ball:
•State (ball state)
Set these up:
You can set the ball size and text to whatever you’d like. If you take the If statement out of the “When Pressed” block it will make it so you can move the ball when it is still rolling.
Next, get this:
This will set the state to 2 when the player releases their finger off of the screen. Credit and thanks to @Funky_63_Greenland for this technic.
This will run when the player lifts their finger off of the screen. It sets the X Velocity and Y Velocity to a number in which is multiplied by the velocity. The X Velocity and Y Velocity only change when they hit a wall, but otherwise they don’t.
The rest of the velocity value:
Set the positions, and movement of the ball.
These slow down the ball.
This stops it, and sets the state to 0 so that the player can move the back again.
And finally, the bouncing off of the walls/borders.
Each one has a “When (State == 3)” before the And.
So when you drag on the ball, it should roll, bounce off the borders and come to a gradual stop.
Completed project if you’d like to see it and/or try it yourself: