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