Scrolling Platformer Tutorial | Part 3 | Platform Detection

griffpatch · Beginner ·🛠️ AI Tools & Apps ·7y ago

Key Takeaways

Adds ceiling and wall detection to a scrolling platformer game in Scratch, corrects scripts for walking up slopes, and adds extra level costumes to make the level larger

Full Transcript

hi I'm Griff patch welcome back to my scrolling platform or tutorial for scratch this is part 3 and today we are going to be looking into making our little platformer more robust or platforming tasks so let's start right away and what we're going to do is we're going to make our level a little bit more interesting so that we can see where the common platformer is letdown so let's change our costumes let's duplicate the level so we now got level 1 2 and we'll use this one for now so we don't raise our original one and we'll add in some more obstacles so what we're gonna add in is a slope on one side we can add in its choose another color a roof on this side and hold down shift there so I get a perfect line okay so we've got a bit more of an interesting level around the guy now let's go back into our person and play this game now when I move around up here all is fine I go down here I jump up yeah I can jump up straight through the wall there floor and if I walk up the slope that seems to work at the moment I walk up to this wall whoa straight up to the top not good so we need to fix all these things the first thing I'm going to fix is the jumping up through the ceiling that's the most easy to fix so let's go to our scripts what we need to change is to change player Y custom block now the reason this is all going wrong is that the script that says if you're in a platformer you have to move up to get out of it so if I'm jumping up from below that's not useful because unfortunately jumping up from below moving up obviously pops you out from the top of the platform so that's no use so we need to change this little bit of script here so that it knows which direction to push you if you touch the platform safely jumping up it pushes you down back out if you're coming down it pushes you back up so to do that let's get an if/else block we pop it right at the start hold on before we do this it's worth mentioning you should stop your project the problem with editing this sort of script while you're playing the game is that if it's running with a always it called if you're running it with the run without screen refresh ticket which we are in one of our blocks then if you change the scripts in here and it runs you can cause a loop that's so fast that it causes scratch to have a bit of a problem so stop your scripts here and we'll do it carefully then so what we're gonna move is the position block underneath this if the change Y is going to go into the if put them back in here okay so we've got the F at the start then we've got opposition part and we've got to change Y in them so we need the greater than symbol and what we're going to say in here is if the speed that we're moving us by is bigger than zero now what that means is we're moving up speed of positive speed it's moving upwards so if we're moving up we want to change the y by minus one so move him down again duplicate that into the second health part and so if we're moving up we move them down if we were moving down we want to reverb so put that one to one okay so we've got to change Y by minus one and they change Y by one it's just a nut again just to see what happens so now if I go into even jump uh-huh success he's not jumping through but one thing that is happening if I hold the up key yeah that could be a useful feature in a game but it wasn't what I wanted and the reason that is happening is that in our little loop down here we set in air to zero it means that if we hit something we assume we on the ground but we're not on the ground when we hit that I heads we should only be on the ground if we hit our bottoms so we need to move that in air from there to put it into this if here so it's only if I character is moving down and we hit something that we set in air to zero so now if we jump uh-huh there we go perfect it doesn't stick anymore and we can jump up here right so that's fixed our first problem of double jumping into roofs but now we have more problems so let's have a look what these are what about walking up a slope seems to work still how about walking into a wall nope so walking into a wall is our next issue to fix we need to stop him from jumping right up to the top so in essence what we need to do when we walk sideways need to check to see whether he's hit a wall and move him out this is very similar to this script we used for falling through a platform so let's see if we can make use of that fact what we're going to do is look for the give me a tick custom block and we've got the if left key change X right key change X so we're going to create a new custom block to use instead of this change X and we're going to call it change layer X by by the options down and add in Essex into there click OK ok this is just like our change but our Y and we're going to use this now so make sure you truth or might want to change play of X where we would change our X before let's use this so pushing pass in minus 8 again take that change X out and duplicate that and we'll change X by 8 when you move right I stopped this nope see I told you I warned you press stop right so this change player X by is going to be very similar to our change why in fact so similar them for now let's let's duplicate it and we'll pop it in here but what we need to do is make sure we change all of the s X's and s Y's and the y's and x's so make sure we're changing by SX not sy and the comparison is SX nice why get rid of these s Y's and then this bit here is change X by we don't need the NS let's get rid of that beat until not touching platform if speed X is bigger than the zero and change X by minus one otherwise change X by one get rid of the in air reposition and get rid of the chain Spets speed why it sounds a bit more cut down but that should be the first first cut of this so let's see if this works that's make it big again play our project so let's try walking to the wall uh-huh we do appear to be stuck there and not able to walk through it that's great hey Jai that's good can't go through the floor but what about slope yeah the thing that was working all along now doesn't work because anything that's any kind of incline at all which is what this big wall is stops us so we stopped by slopes now so we need to get making another change to our scripts support slopes now stop our project and have a look so you need to modify this change player X script and what we need to do is have some extra checks in here before we stop the player and move them away so the best way to do this is to get an if block and put it right way around the entire script under position and we're gonna need this touching platforms pop it in there so it's only gonna run this bit here if we're touching up that form when we walk sideways into one but what we want to do is to see whether when we walk across to the slope whether we can move ourselves up a little bit out of the slope if we find that we can move ourselves up then that's great we'll let it do that but if we walk into a big wall and we move myself up it don't say no we can't do that because we're not out of the wall we have to move up all this way to get out of the one we don't want that so we're going to let ourselves move a little bit up and see whether there's space so what we'll do is we'll have a repeat loop that's going to be repeat eight so eight pixels we're going to try which is just a little tiny bit just enough it's the same speed that we're walking sideways it's why I chose it so it means if we walk across eight we can move up eight so it's a nice 45-degree slope so wouldn't that repeat eight we need to change our Y position to move upwards so change Y by want so we've up my one then we need to position like that and then do a check to see whether it in a platform so again another if and check to see whether we're not in a platform yeah and if we're not in the platform then we're okay we're actually out of the platform on this scripts all want to stop let me show you this now if I move this whole script I put it into the here just before the other repeat okay so if you're touching a platform we loop around moving up eight times and if any point we're no longer in a platform we want to stop and come out of this custom block that can be done using this stop block but not stop all that stops the whole program we want to stop this script so this is the effect of moving me up and then as soon as when out of a platform we come out and that's great because that's what we wanted we've walked into a slope move this up and we help however if at the end of this eight move ups we're not out of the platform then we've probably hit a wall so we want to go back to doing what we did before and shaking and pushing us out of the wall back to where we were but before we can do that we realize that we've reviewed us us up by eight one eight times so we need to move ourselves back down eight times quickly so we need another change just in here at the end of the loop and it's going to be y by minus eight yeah so we've repeated around eight times going up and then move yourself back down eight and then if we have move down we then repeat the checks to push us back out of the slope so let's see if that works run that so we run into a wall all's good and the big moment ah fail it starts to seem to work and then it doesn't could it be that this slope is actually slightly taller than 45 degrees probably so in that case we might need to tweak this eight let's try adding this to 12 instead and again minus 12 here try again here we go so this sleigh was actually too steep but now it works so you need to tweak that value to find a good one that works for your game let's try this wall yeah all good I think we have a good stable platform now this is looking really good much more like what we wanted originally okay so that was the main purpose of this tutorial to get this point but I thought what might be nice is just to add a little bit more level on just to make it a bit more exciting for you before I leave it for the next tutorial so let's do that go into your platforms so we've already now got level 1 point 1 and level 1 too so let's add a third one in so duplicate that again so it's nice it's doing the numbering for words like this which is great it has changes level slightly so it's interesting let's draw another line going up from this platform like this and maybe change this line of it here too what should we do do that okay so we've got three bits of level so let's go into the scripts write what we haven't done is added in here the set up custom block which we already call broadcasting but we're not doing anything with it so how did I set up that I'll just move this tick up here out of the way I mean set up we want to do our cloning and positioning of the level pieces so for starters we need some set X and set Y's so set X and set Y to 0 to begin with which is in the middle so this level here will appear in the middle where the screen of the game and also switch the costume to the first costume of the level ok all good so that one just as they did before originally with our first part of the level now we want another piece of the level next to it so for this we need to start using clones under the control let's see create clone of myself so that means we now got two copies of this level and what we shall do now is script to move this bit of level so we will change X by will say 360 for now so we're moving it to the second one across by 360 and we will switch to the next costume as well so next costume case we would not now there we go so now we've got this bit of level and we've got the next bit of level and what if we want another one well it's easy now so we just gonna duplicate of this clone change X and the next costume and run it again now we have the neck bit of level so there are three pieces of level one after the other very easy very quick your course will have been noticing that on the Left we have a bit of an artifact but as we go along these bits on the left and light remain you can still see them poking across this is the bane of a scratchers life when it comes to scrolling so you'll see lots of projects with white or black borders around them to hide this little overlap over the previous bits of level or there's another way of doing things just to hide them as they go off the screen but that is not for this tutorial I'm afraid sorry about that you can design some levels have some fun but you have to put up with that edge or draw a little border around it so that you can't see it but next tutorial we'll go into how I will hide it for this game and I hope these lots more so thank you again for watching see you guys bye

Original Description

This is part 3 of this tutorial series where we are building a scrolling platformer game together. (Part 1 can be found here: https://youtu.be/sebnyhBsXug). In this tutorial we add in ceiling and wall detection, plus corrected scripts for walking up slope. At the end of the tutorial we then quickly add in extra level costumes to make the level larger. Part 4 is now available here: https://youtu.be/5brqYa7LI88 🚀 *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
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from griffpatch · griffpatch · 6 of 60

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
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
60 Tile Scrolling Platformer | 15. Crouch & Slide
Tile Scrolling Platformer | 15. Crouch & Slide
griffpatch

Related Reads

Up next
Perfect Academic Writing with Thesify AI Tool (Papers & Proposals)
Educraft
Watch →