This tutorial shows how to make a simple physics engine where the sprite is not controlled by the arrow keys, as in Platformers, but rather interacts like dropping and pushing the Sprite in real life would.
First make the following Variables 'for this sprite'
Next make two sprites, one will be the one that uses the physics, and the other will be the one will be the ground that the sprite interacts with. In this tutorial, all the scripts are used in the main sprite and the ground sprite is called 'ground'.
Collision Detection
First, collision detection needs to be made. The collision detection that will be used is similar to ones used in platformers, however, this script does not use any controls to move the player.
Turning When Hitting a Slope
This script will make the sprite fall toward the ground and not go through it, however, this does not give a realistic physics look because the sprite does not turn or move on slopes. To add turning and sliding down slopes, another custom block needs to be made, called Turn:
Now that the turning custom block has been created, it needs to be used:
Implementing Code
The turning and collision detection has been created, so the only thing left to do is to use it.
Final Code
Шаблон:Note
Here is the final code for the physics engine: