Tile Scrolling Platformer | 15. Crouch & Slide

griffpatch · Beginner ·🧒 Coding for Kids ·5y ago

Key Takeaways

Griffpatch implements crouching and sliding mechanics in a tile scrolling platformer, adjusting the player's hitbox and discussing potential solutions for stuck situations.

Full Transcript

[Music] hello fellow scratchers i'm griff patch this is going to be a short tile scrolling tutorial today because i'm on my holidays woohoo so what are we adding crouching and sliding cool so let's get to it we'll begin by adding support for the down key to begin a crouching action the best place for this is in the existing handle keys jump costume block yeah it's not jumping but it is an up and down movement so we'll rename the custom block to be handle keys jump slash crouch okay we'll separate off the if up block and below and we put in a new if else block here checking for the down of controls being greater than zero if you remember all our key controls are coded in the control sprite now we only want to crouch if we are on the ground not while falling through the air so another if checking whether falling is less than two we are either on the floor or have just been there now we simply set player action to the word crouch this is great as we will now be able to check whether mario is crouching by looking at the player action anywhere else in the code for example to set the costume next up set jump to zero since we are definitely not jumping now so what about when we have let go of the crouch key we check for this in the else where the down key is not pressed if else and check for player action equal to crouch if it was then we'll try setting player action back to the empty value meaning that mario is no longer crouching finally in the second else we are not crouching so bring back the original jumping scripts before we can test this we need to get mario's costume to change too find the define paint sprite and you can see we are already doing a similar thing with the player action of the lose life here we can duplicate that if condition and check instead for a player action of crouch then switch the costume to mario crouch ensuring we still follow that with a stop this script superb let's give that a test press the down key and there you go a brilliant little crouch action right away so can we stop there are we done no i don't think so behold my awesome new crouching sliding mechanic yeah we can still walk around whilst crouching hilarious to watch but not something we want to keep long term however since we can slide now easily around the level let's make use of this to test another required feature of the crouch that of being able to slide into smaller gaps for this we should make some small changes to the level to create a one block high tunnel something like this and now if i slide towards this new obstacle we can see that we have yet some work to do here although mario's costume is the correct size to go through the gap his hit box is not come with me to the define fix collisions in direction script this is where we check six points on mario the bottom left and right middle left and right and top left and right points we could when crouching change the height variable such that mario was shorter but if we do that then mario's feet will lift off the floor since we are centered around the middle point for ease then how about we just stop checking for the top two collision points whilst crouching that would reduce our hitbox by half in height whilst keeping it positioned on the screen correctly we'll start by rearranging the order of these fixed collisions at points so that the second values are paired together there feet first then their middle and then their head good and now surround the last two checks these are the top checks of where mario's head used to be and surround them with an if and we'll only check this when mario is not crouching not player action equals crouch it's testing time so run the project we can start by making sure that we are still prevented from walking into this gap when standing up straight and now crouching yes that's really good our small size lets us slip through the gap now very very good so this means we can now get into a position we couldn't before and that is to be crouching under a block we then have to consider what will happen if we let go of the crouch key while we are still under this block ah so that's what happens as soon as we stand up our hitbox suddenly is in contact with the level and things go a bit crazy popping us up through the level out of the ceiling above what we really want to do here is prevent us standing up again when there is no room to do so come back into the define handle keys jump crouch script here is when we handled the crouch key press and here is where we get back up again by setting the player action to the empty value we are going to need to do a little bit more work before we allow mary to stand up so i think it best we create a new custom block naming it handle get up we'll switch it around to now use this in place of the set player action there okay so at this point mario will have got up we should take this opportunity to check whether we are colliding with anything but remember that checking for collisions will also move mario out of the collision so let's keep track of their current position in the orig y variable first so that we can restore it afterwards orig y stands for original y so the original position set of y to y now we use fixed collisions in direction dx of 0 and dy of 1 as our head is moving upwards we can then check if we bumped our head if solid is greater than 0 right so if we did bump our head then this is no good we need to crouch back down quickly set player action back to crouch and remember to restore our y position back to orig y so that we stay where we were now before this will work and there is another fix we must make come with me up to the define handle keys left right script look here we are setting player action to walk right at the top this is no good because this undos our good work of keeping the crouch action set this needs to change a little to account for crouching too add an if else block right at the top and check if player action equals crouch the rest of the scripts can be placed into the else below nice let's run the project and check that out okay this is interesting now when i slide underneath i can no longer get up but i also continue to slide all the way through and can not stop ha we need to begin by making mario slow down when he's crouching first we'll check whether they are moving at all if the absolute value that's the abs abs of speed x is greater than 0.4 that means the speed is greater than 0.4 or less than minus 0.4 then we want to slow down by 0.4 towards zero we could do that with an if else let's do it with maths change speed x by negative 0.4 multiplied by speed x divided by and then the same abs of speed x there dividing a number by the absolute value of itself will result in either a one or a minus one if the number was negative quite a useful thing to remember that means speed x will be changed by either minus 0.4 or 0.4 after the multiply slowing the player down next add a make skid smoke for extra effect now in the else we can ensure we are now stationary by setting speed x to zero and setting player frame to zero two to keep the animations in check i'm testing this now oh yeah so crouching is now looking much more cool and i slide to a stop and i have particle smoke of course there is then one question remaining what happens if i slide under ah yes just what i was wondering as i'm crouching and cannot move and i cannot get up i am so stuck oh no yeah well we have three options here we say too bad and lose the player alive but that would be cruel we could keep the player sliding like we did previously so they always make it out the other side that would be okay but it wouldn't make any of these sliding obstacles a challenge so the third option the one we will take is that we will force the player back out the way they came find the define handle get up script when the player is trying to get up but their head is colliding that's here we will change their speed x by direction that will be 90 or minus 90 depending which way they are facing then we can divide that by minus 200. i just picked a good value here by trial and error negative so that they move backwards from under the block come on then let's give it a test i'll slide under the first block oh yes did you see that it was subtle but mario definitely slid back out i'll take a longer run up yeah there you go you can see it working in all its glory there as we slid right back out excellent work and dare i say it we are done for this short episode i hope you enjoyed it and if so then please do hit the like button i'll keep trying to get the tutorials out over the holiday season so do subscribe to catch them as they become available until next time though thank you for watching and scratch on guys [Music] [Music] you

Original Description

A short episode today as I'm on my holidays :) - We add in crouching and sliding to the tile scrolling platformer. We also learn to change our hitbox for the new size, and think of ways to get out of situations where we might get stuck! 🚀 *Boost Your Creativity with Griffpatch* The Griffpatch Academy will take you from "Gamer to Game Creator" Learn more at 👉 https://griffpatch.academy 👈 😺 Scratch was developed by the Lifelong Kindergarten Group at the MIT Media Lab. See http://scratch.mit.edu 🐱 Scratch Starter Project Game Assets https://scratch.mit.edu/projects/485855713/ 🐱 Complete Ep.6 Scripts https://scratch.mit.edu/projects/522557780/ 👀 Playlist of all Tile Scrolling Platformer Episodes: https://youtube.com/playlist?list=PLy4zsTUHwGJIc90UaTKd-wpIH12FCSoLh ❤️ Enhanced Scratch Developer Tools https://www.griffpatch.co.uk/ 📹 The Awesome Video Editing software I use (Camtasia) https://techsmith.z6rjha.net/5bajbo --------------Video Chapters-------------- 0:00 Intro 0:16 Crouching Key 1:47 Costumes 2:53 Crouching Hitbox – Fitting though small gaps 4:31 Standing Back Up 7:09 Slowing Down 8:54 Getting Unstuck 10:13 Outro
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from griffpatch · griffpatch · 60 of 60

← Previous Next →
1 Burrow Blitz - A game by Griffpatch
Burrow Blitz - A game by Griffpatch
griffpatch
2 Burrow Blitz Level 1 Speed Run!
Burrow Blitz Level 1 Speed Run!
griffpatch
3 Scratch Messaging Extension (for chrome & firefox)
Scratch Messaging Extension (for chrome & firefox)
griffpatch
4 Scrolling Platformer Tutorial | Part 1 | Get Scrolling
Scrolling Platformer Tutorial | Part 1 | Get Scrolling
griffpatch
5 Scrolling Platformer Tutorial | Part 2 | Gravity
Scrolling Platformer Tutorial | Part 2 | Gravity
griffpatch
6 Scrolling Platformer Tutorial | Part 3 | Platform Detection
Scrolling Platformer Tutorial | Part 3 | Platform Detection
griffpatch
7 Scrolling Platformer Tutorial | Part 4 | Off Screen Sprites and Player Death
Scrolling Platformer Tutorial | Part 4 | Off Screen Sprites and Player Death
griffpatch
8 Scrolling Platformer Tutorial | Part 5 | Collectables
Scrolling Platformer Tutorial | Part 5 | Collectables
griffpatch
9 Scrolling Platformer Tutorial | Part 6 | Danger Sprites (Bug fix)
Scrolling Platformer Tutorial | Part 6 | Danger Sprites (Bug fix)
griffpatch
10 Scrolling Platformer Tutorial | Part 7 | Exit Portal
Scrolling Platformer Tutorial | Part 7 | Exit Portal
griffpatch
11 Scratch 3 | Box2d |  Physics Extension
Scratch 3 | Box2d | Physics Extension
griffpatch
12 Scrolling Platformer Tutorial | Part 8 | Vertical Scrolling
Scrolling Platformer Tutorial | Part 8 | Vertical Scrolling
griffpatch
13 Zombie Cube | Speedrun challenge
Zombie Cube | Speedrun challenge
griffpatch
14 Scratch 3 | Physics Extension | Version 2
Scratch 3 | Physics Extension | Version 2
griffpatch
15 Top Down Scroller | E1 - Scrolling | Scratch Tutorial
Top Down Scroller | E1 - Scrolling | Scratch Tutorial
griffpatch
16 Top Down Scroller | Part 2 | Enemy AI
Top Down Scroller | Part 2 | Enemy AI
griffpatch
17 Top Down Scroller | Part 3 | Enemy Clones & List
Top Down Scroller | Part 3 | Enemy Clones & List
griffpatch
18 Top Down Scroller | Part 4 | Live Die Repeat (Game Over)
Top Down Scroller | Part 4 | Live Die Repeat (Game Over)
griffpatch
19 Top Down Scroller | Part 5 | You've Won!
Top Down Scroller | Part 5 | You've Won!
griffpatch
20 Cloud Game Tutorial | Part 1 | The Basics
Cloud Game Tutorial | Part 1 | The Basics
griffpatch
21 Cloud Game Tutorial | Part 2 | Encoding and Decoding
Cloud Game Tutorial | Part 2 | Encoding and Decoding
griffpatch
22 Scratch 3 Dev Tools Browser Extension by griffpatch
Scratch 3 Dev Tools Browser Extension by griffpatch
griffpatch
23 Cloud Game Tutorial | Part 3 | Multiplayer
Cloud Game Tutorial | Part 3 | Multiplayer
griffpatch
24 Scrolling Platformer Tutorial | Part 9 | Momentum
Scrolling Platformer Tutorial | Part 9 | Momentum
griffpatch
25 Scrolling Platformer Tutorial | Part 10 | Wall Jumping
Scrolling Platformer Tutorial | Part 10 | Wall Jumping
griffpatch
26 Cloud Game Tutorial | Part 4 | Auto Game Joining
Cloud Game Tutorial | Part 4 | Auto Game Joining
griffpatch
27 Game Preview - "Getting Over It" with Griffpatch - A fan recreation in Scratch
Game Preview - "Getting Over It" with Griffpatch - A fan recreation in Scratch
griffpatch
28 Speed Run with Outtakes | Getting Over It | 4 minutes 30 seconds
Speed Run with Outtakes | Getting Over It | 4 minutes 30 seconds
griffpatch
29 Griffpatch's Live Stream
Griffpatch's Live Stream
griffpatch
30 MMO Platformer Speedrun Challenge
MMO Platformer Speedrun Challenge
griffpatch
31 Appel Platformer | Scratch Game Blog
Appel Platformer | Scratch Game Blog
griffpatch
32 Cloud Game Tutorial | Part 5 | Smooth Movement
Cloud Game Tutorial | Part 5 | Smooth Movement
griffpatch
33 How to Design a Level for Appel
How to Design a Level for Appel
griffpatch
34 Fastest Appel Speedruns | Jan 2021
Fastest Appel Speedruns | Jan 2021
griffpatch
35 Tile Scrolling Platformer (Mario) | 1. Setup
Tile Scrolling Platformer (Mario) | 1. Setup
griffpatch
36 Tile Scrolling Platformer | 2. Grid List
Tile Scrolling Platformer | 2. Grid List
griffpatch
37 Tile Scrolling Platformer | 3. Tile Collisions
Tile Scrolling Platformer | 3. Tile Collisions
griffpatch
38 Tile Scrolling Platformer | 4. Platforming Scripts
Tile Scrolling Platformer | 4. Platforming Scripts
griffpatch
39 Tile Scrolling Platformer | 5. The Level Editor
Tile Scrolling Platformer | 5. The Level Editor
griffpatch
40 Tile Scrolling Platformer | 6. Level Codes
Tile Scrolling Platformer | 6. Level Codes
griffpatch
41 Tile Scrolling Platformer | 7. Drop Through Platforms
Tile Scrolling Platformer | 7. Drop Through Platforms
griffpatch
42 How to make Physics in Scratch | Full Tutorial
How to make Physics in Scratch | Full Tutorial
griffpatch
43 Tile Scrolling Platformer | 8. Enemy Clones
Tile Scrolling Platformer | 8. Enemy Clones
griffpatch
44 Simple Pathfinding Tutorial
Simple Pathfinding Tutorial
griffpatch
45 Tile Scrolling Platformer | 9. Enemies in Level Editor
Tile Scrolling Platformer | 9. Enemies in Level Editor
griffpatch
46 Simple Maze Generation | Scratch Tutorial
Simple Maze Generation | Scratch Tutorial
griffpatch
47 Tile Scrolling Platformer | 10. Mystery Blocks
Tile Scrolling Platformer | 10. Mystery Blocks
griffpatch
48 Simple Car Steering Simulation | Scratch Tutorial
Simple Car Steering Simulation | Scratch Tutorial
griffpatch
49 Simple Background Scrolling Tutorial
Simple Background Scrolling Tutorial
griffpatch
50 Tile Scrolling Platformer | 11. Death, Background & Sound
Tile Scrolling Platformer | 11. Death, Background & Sound
griffpatch
51 Mid Week Update & Channel Membership
Mid Week Update & Channel Membership
griffpatch
52 Simple Grid List Tutorial with Image Scanning
Simple Grid List Tutorial with Image Scanning
griffpatch
53 Tile Scrolling Platformer | 12. Auto Arranging Tiles
Tile Scrolling Platformer | 12. Auto Arranging Tiles
griffpatch
54 Code a Fun Space Shooter Game 🚀 | 1. Move & Shoot | Scratch Tutorial
Code a Fun Space Shooter Game 🚀 | 1. Move & Shoot | Scratch Tutorial
griffpatch
55 Space Shooter 2 - Enemy Collisions
Space Shooter 2 - Enemy Collisions
griffpatch
56 Tile Scrolling Platformer | 13. Level Progression & Editor Improvements
Tile Scrolling Platformer | 13. Level Progression & Editor Improvements
griffpatch
57 Space Shooter 3 - Camera Shake & FX
Space Shooter 3 - Camera Shake & FX
griffpatch
58 Tile Scrolling Platformer | 14. Sloping Tiles
Tile Scrolling Platformer | 14. Sloping Tiles
griffpatch
59 Pathfinding a Maze using Lists
Pathfinding a Maze using Lists
griffpatch
Tile Scrolling Platformer | 15. Crouch & Slide
Tile Scrolling Platformer | 15. Crouch & Slide
griffpatch

In this video, Griffpatch adds crouching and sliding to a tile scrolling platformer, teaching kids how to adjust the player's hitbox and think critically about game development. The episode covers practical coding concepts and problem-solving strategies for young developers.

Key Takeaways
  1. Create a new platformer project
  2. Implement crouching mechanics
  3. Add sliding mechanics
  4. Adjust player hitbox for new size
  5. Test and refine the game
💡 Adjusting the player's hitbox is crucial for smooth gameplay and preventing stuck situations.

Related Reads

Chapters (8)

Intro
0:16 Crouching Key
1:47 Costumes
2:53 Crouching Hitbox – Fitting though small gaps
4:31 Standing Back Up
7:09 Slowing Down
8:54 Getting Unstuck
10:13 Outro
Up next
How to Open PXT Files (Microsoft MakeCode Project)
File Extension Geeks
Watch →