Simple Wall Detection in Scratch
Below are three methods to create walls that your character can't go through!
This post is using projects created on Scratch, which is a free, open-source software found at https://scratch.mit.edu/.
Step 1:
|
Test out this example.Instructions: Click the flag at the top of the player, and use your mouse to move the cat around. Notice that you cannot go through the block in the middle of the stage. |
Step 1:Create a level with a solid color for the "walls", in this case it'll be grass. |
Step 2:Create a character with a certain color ONLY on the front. |
Step 3:Add this code to your character. Make sure to adjust:
|
Step 1:Create a wall sprite. No need to add any code to itStep 2:Add this stack of code to your character that's not supposed to go through walls.Choose 1 of the following stacks for your arrow key controls and give it to your character. One uses X/Y the other uses direction-based movement.
|
Test out this example below.Instructions: Click the flag at the top of the player, and use the arrow keys to move the dinosaur around. |