Let's do a little thought experiment. What is the simplest way to make an object fall? We could start by constantly changing its y position, like so:
|Change y position of the object at each loop iteration|
|Using a variable to contain the downward displacement|
|Increase downward displacement at every loop iteration|
That was actually all the code we need to simulate a falling object.
Making the Scratch sprite landMost of the time, we would want the object to be able to land on the ground (or something else, anything). How can we program landing with Scratch? Let's think about this again.. When we jump off a chair in the physical world, why are we able to land on the ground and not sink further in? After all, we are always acted upon by gravity, meaning that we are always pulled towards the centre of the Earth. So why not sink further in?
The scientific explanation for this is that the ground exerts a force equal to the gravitational force on us. The two forces cancel leaving us stationary, since there can be no further movement without a force.
We can use the same concept in our script. We insert statement blocks to cancel out the falling distance (i.e. the v variable) when the object is on the ground.
I will suppose that when our object touches the ground, its y position is -80. So I will use the condition if y position < -80 to determine whether the object is on the ground. We could of course use other means, like the sensor blocks for example.
Here is the complete script: