Scratch Wall Collision | How to Make Sprites Not Go Through Walls

Sdílet
Vložit
  • čas přidán 6. 09. 2024

Komentáře • 526

  • @snabban9436
    @snabban9436 Před 2 lety +20

    I Like how you explain why it works instead of just showing so people learn. This helped alot thanks!

  • @jumpingpunchingman234
    @jumpingpunchingman234 Před 3 lety +23

    Thank you so much!I have been struggling for a way to not go through walls.

  • @dalegend6470
    @dalegend6470 Před 3 lety +10

    Thanks so much, my teacher gave me code that
    1. Teleported my sprite
    2. Had the WALLS AS A BACKDROP
    Dun dun dunnnnnnnn

  • @ohnohwgn
    @ohnohwgn Před 3 lety +9

    this tutorial is good, but if you want more precise collision (especially for faster movement), replace the speed(-1) inside of the touching collision script to
    repeat until not touching (your colliding block)
    if speed < 0 then
    change x by 1
    else
    change x by -1
    do the exact same thing for y but replace x with y
    if i explained it too confusing i can post an imgur of what i did

    • @ohnohwgn
      @ohnohwgn Před 3 lety +2

      note that this wont always be exact and there might be a very small amount of space between you in the wall but it will prevent much larger gaps from becoming an issue
      also, something i noticed when testing this was that it shoots you out of the wall if you suddenly become stuck inside of it

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +2

      Hmm... My project works fine. I wonder is going on!

  • @SpongeBobFan-li4qd
    @SpongeBobFan-li4qd Před 3 lety +4

    My character gets stuck on the wall, then if i hold right arrow to get out of the all it will make me move left inside the wall

    • @SpongeBobFan-li4qd
      @SpongeBobFan-li4qd Před 3 lety +1

      Nevermind i figured it out, when i pressed the left arrow key my character would face -90 degrees making him clip into the wall.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +3

      Great! I'm glad you figured it out!

  • @Kinguardia
    @Kinguardia Před 2 lety +3

    ok sir, I'm 18 years old trying to make a game, and I got stuck on how the heck to do collision detection when my sprite wasn't a square. I don't know if this was intentional, but your code works with circular objects as well. bravo my good sir.

  • @Derplie
    @Derplie Před 3 lety +2

    Ive been trying to think of a way to get wall collision to work for an AI. Im making a pacman game and obviously if you are pacman and you go into a wall you're a human so you realise "ah this is a wall and i cant go through it so lets not go into a wall again" but if its an AI (by AI I mean a ghost with a glide script to glide to the pacman x and y) its going to keep wanting to try the same route over and over again. Basically what I need the ghost AI to do is to make it realise that after going into a wall it needs to get a different route. This would require a custom block though as the normal glide block only comes up with 1 route.
    Basically I need a ghost that goes to pacman while avoiding the walls of the maze.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +2

      Hmm... I know how to make it stop when it hits the wall, but to make it move around the wall means to make advanced pathfinding! I am not smart enough for that! xD

  • @SpaceCat22
    @SpaceCat22 Před 2 lety +4

    everything works,but when it gets to the wall it has a little gap

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      Hm, maybe try the updated tutorial: czcams.com/video/OmRh6SXoI0Y/video.html

  • @meltrix4319
    @meltrix4319 Před 3 lety +2

    This didn't work for me. I did all the steps but it kept being jank and getting me caught in the wall. Any ideas?

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety

      You can check out the code here: scratch.mit.edu/projects/569868885/

    • @bhavinrasania5084
      @bhavinrasania5084 Před 3 lety +1

      @@ShiftClickLearn thank you so much I want to make my open-world game and it helps so much I was finding a perfect tutorial and I find it

  • @jeditz8
    @jeditz8 Před 3 lety +7

    ninja is in the thumbnail

  • @ElhamEbrahem-u1u
    @ElhamEbrahem-u1u Před měsícem +1

    Finally a Pro way to make colisions, rpg scrolling and customizable movement speed🎉❤ I like it and I love it❤❤

  • @pandaking_DK
    @pandaking_DK Před rokem +7

    This is so smooth. I love it. And the movement is great aswell!

  • @CapybaraStudios
    @CapybaraStudios Před 2 lety +3

    I am making a stealth game, and I am using the scrolling method. I would like to make enemies that follow a set path, but they are moving with player, so it is broken. How do I make the enemies move separately?

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      They need to have their own for this sprite only x and y variables! :D

    • @CapybaraStudios
      @CapybaraStudios Před 2 lety

      @@ShiftClickLearn Ok, do you mean like make new variables called X ad Y? I'm not that good at scratch.

  • @arctix____
    @arctix____ Před 2 lety +3

    thank you so much! i still dont understand how creating blocks work, let alone how this code functions, but it worked in the end so thank you.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety +1

      Glad it helped! If you would like to learn how to use custom blocks, check out this video: czcams.com/video/SMUtkMuGi-w/video.html

  • @WesleyExtreme_Gamer
    @WesleyExtreme_Gamer Před 2 lety +7

    GEEZ man , this logic is so GENIUS, I never looked at these customizable blocks as being so useful this way, this video really opened up thousands of new possibilities for me to do in Scratch, Thanks man :D

  • @killthepoets_
    @killthepoets_ Před 2 lety +4

    thank you so much for the explenation at the end! awsome video!

  • @jakesecreto
    @jakesecreto Před rokem +2

    Do these movement and collision scripts work on platform games? If yes, how could I add gravity and jump? I mean, I've found some other videos about collision but they use color detection which is not that good. Thanks!!

  • @sayyidassons9332
    @sayyidassons9332 Před 2 lety +2

    thanks super helpful im trying to make a rpg and i dont know to to make scrolling collision till i saw this video thanks really helpful

  • @Aether558
    @Aether558 Před 2 lety +5

    My games used to all be non-platformers until i found this video

  • @MrNimaSamimi
    @MrNimaSamimi Před 3 lety +8

    Terrific video, thanks Owen! You were super clear and you made sense of a very confusing piece of code. I really appreciated it.

  • @baconbread2160
    @baconbread2160 Před 3 lety +9

    This is some delicious code. Thank you for helping me make my yummy game.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +5

      Glad I could help you to make a scrumptious game!

    • @kaveyalt
      @kaveyalt Před 3 lety

      is this game about fricking cooking or something

    • @membles69
      @membles69 Před 3 lety +1

      @@kaveyalt It’s obviously delicious!

  • @esqueleto8545
    @esqueleto8545 Před 3 měsíci

    Dude, that was the only video that really helped me do week 0 of cs50.

  • @alistaircox8003
    @alistaircox8003 Před 2 lety +4

    this was very helpful, thanks

  • @shahinma221
    @shahinma221 Před 3 lety +3

    Thank You! You Just Helped Me For My Game Which Needs Wall Collision!

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +2

      You are very welcome!

    • @shahinma221
      @shahinma221 Před 3 lety +2

      Also, Thank You Not Only For This, But For All UR Helpful Video's, Just Like Griffpatch :)

  • @P1ctured
    @P1ctured Před 2 lety +2

    Hello will using this I found and error for me. The change x/y by speed x -1 didn't work when I tried to move backwards away from a wall it would move me in the in the other direction towards the wall so I couldn't escape. This is because since it's -1 it goes in the other direction do you have anything to stop this.

  • @alexthedumb1843
    @alexthedumb1843 Před 3 lety +2

    how do you make it so you can rotate while moving

  • @Al13NZzzz
    @Al13NZzzz Před 3 lety +2

    im making a game and im planning big things for it and this helped me so much

  • @zerkuya9540
    @zerkuya9540 Před 3 lety +2

    This code is so BEAUTIFULL !

  • @alpactra1830
    @alpactra1830 Před 3 lety +2

    Im not used to making blocks and i dont really know how they work so it baffled me when it worked lol xD

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +2

      Well, I'm glad it worked! If you want to know a little more about using custom blocks, you can check out this video I made on them: czcams.com/video/SMUtkMuGi-w/video.html

    • @alpactra1830
      @alpactra1830 Před 3 lety +1

      @@ShiftClickLearn thank you

  • @Veiroww
    @Veiroww Před 2 lety +3

    Thanks so much! This really helped me with my game :)

  • @boysok456
    @boysok456 Před 2 lety +2

    it worked but it stopped working like i couldn't get my sprite to walk up and down, only left and right. do you know why? please help

  • @Kemuri2946
    @Kemuri2946 Před 2 lety +2

    So I followed it and I can't go through the walls but when I touch them it makes it so I can't move even if I press the WASD keys, which are the keys I'm using

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      Maybe try my updated tutorial: czcams.com/video/OmRh6SXoI0Y/video.html

    • @silasporter5497
      @silasporter5497 Před 2 lety

      its because your not using a hit box. instead, your using the spirit that moves around.

  • @indigoesgaming
    @indigoesgaming Před 2 lety +3

    Hey man, I was trying to do this but kept failing so I was gonna scrap my game. But your video helped me solve it!
    Thanks for helping :D

  • @ShiftClickLearn
    @ShiftClickLearn  Před 3 lety +18

    UPDATE: I made a new tutorial that's much better, so make sure you check it out here: czcams.com/video/OmRh6SXoI0Y/video.html
    I hope this tutorial helped you guys out with your wall collision! 🧱
    Click the link below to check out the full project:
    scratch.mit.edu/projects/569868885/

  • @ughhehe5449
    @ughhehe5449 Před 2 lety +2

    Can anyone answer this please?
    I am having trouble with another background, I made another background and put the wall collision this on but for the sprite i'm using for the level (I you know what i mean.) I put it on but every time i try to do the level, the wall collision thing did not work.
    Im not sure if its a bug or i'm just being stupid. (or something else)

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      That is really weird.. I checked my code and it still works

  • @hyeenaaa1960
    @hyeenaaa1960 Před 2 lety +3

    It doesn’t work for me for some reason and I’ve tried everything

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety +1

      Try an updated tutorial: czcams.com/video/OmRh6SXoI0Y/video.html
      It has much better code! :D

  • @SpiteAnims
    @SpiteAnims Před 2 lety +3

    really helpful, even outside scratch the logic still helps

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety +2

      Awesome! :D
      I find that the basic logic is similar across many languages!

  • @User-lm1ll
    @User-lm1ll Před 2 lety +4

    thanks for the tutorials

  • @nzdzeni
    @nzdzeni Před rokem +1

    Thanks so much! This is extremely useful. I'm a teacher and I'll be using this with my class to help them set up their games.

  • @certifiedw__a-a--tcher
    @certifiedw__a-a--tcher Před 3 lety +3

    How can i make a sprite that is following the player not go through walls?
    I’m making a Spooky’s Jump Scare Mansion test and i cant get the enemy to not go through walls.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +1

      Could you send me a link to your project?

    • @certifiedw__a-a--tcher
      @certifiedw__a-a--tcher Před 3 lety +1

      @@ShiftClickLearn i figured out a way for it to follow you and not go through walls, but when i make a turn, it gets stuck on the wall.
      Can you help me with that?

  • @KnowGameOffical
    @KnowGameOffical Před 3 lety +3

    Thank you this is the best video and I finally got after hours of research

  • @jacobsquartzminecart7632
    @jacobsquartzminecart7632 Před 2 lety +1

    I found this very helpful for a game I'm making called Steam On The Seven Seas, now your ship can't just go over land!

  • @silasporter5497
    @silasporter5497 Před 2 lety +2

    I Can use this for many of my games! Thanks for Making this!

  • @flamingopool
    @flamingopool Před 2 lety +2

    Hi, this really helped ive got a playlist called good tutorials for my viewers to watch and i added this imediantly tysm it really helped i always wanted to make a platformer/maze game and this rlly helped tysm

  • @drog9235
    @drog9235 Před 2 lety +2

    is there any way to add costume changes to the moving script so i can use a non smooth character

  • @43dl3ntil
    @43dl3ntil Před 2 lety +2

    Tysm!! This helped tremendously with my top-down RPG. I smashed that sub button as hard as I could when the engine worked!

  • @bido64
    @bido64 Před 3 lety +2

    hey! really like this tutorial but what if i want to make multiple different sprites be walls? what do i do?

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +3

      See all the touching walls? Change them to touching wall OR touching wall2 (Or whatever your second wall is named)!

    • @bido64
      @bido64 Před 3 lety +1

      @@ShiftClickLearn Ohh okay! So do i just make a new If box and put it under the already make if touching wall?

    • @ckqk
      @ckqk Před 3 lety +1

      @@bido64 no, get the "and" block and put the "touching wall2" block inside the empty space or whatever the name is.

    • @bido64
      @bido64 Před 3 lety +1

      @@ckqk thank you

  • @UkaSozi
    @UkaSozi Před rokem +2

    Wow,many thanks! Im currently working on a adventure game on a huge map so this is extremely important. THanks again!

  • @RegularBreadFaceIsCoolLmao

    You are the absolute best man
    I'm a beginner trying to make a earthbound style game and this was the one thing I needed (my character controller and collision was trash lmao)

  • @imtiredgoodnight
    @imtiredgoodnight Před 2 lety +3

    Great video, you’re very clever.

  • @iaminfinityiq7182
    @iaminfinityiq7182 Před rokem +1

    Really helpful! Your tutorial does not only help Scratch games but it also helps my Pygame game :D

  • @42p074
    @42p074 Před 2 lety +2

    how though I just go through walls and if I press "D" it resets position
    well damn I might be doing something wrong I think.

  • @tintinroblox
    @tintinroblox Před rokem +1

    This is so goooooooood!!!!! I can finally make a rage game without making people rage! THX!

  • @minecracra7490
    @minecracra7490 Před 3 lety +2

    Simple and useful. Thx

  • @GarfieldLover959
    @GarfieldLover959 Před rokem +1

    im making a game like stardew valley where its at a slight angle is there any way to make it so the top half of the player does not collide with sprites?

  • @HaniwaBun
    @HaniwaBun Před 3 lety +4

    for some reason, when I click the green flag the game just stops admittedly how do I fix this problem?

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +3

      Huh...🤔 It's hard to tell without seeing the code. Would you send me a link the project?

    • @HaniwaBun
      @HaniwaBun Před 3 lety +2

      Ok

    • @HaniwaBun
      @HaniwaBun Před 3 lety +1

      I found the problem but now it wont move when i touch the wall

    • @HaniwaBun
      @HaniwaBun Před 3 lety +1

      Here scratch.mit.edu/projects/516480899/

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +2

      @@HaniwaBun Would you please send me a link to the project?

  • @chrismations9191
    @chrismations9191 Před 2 lety +1

    idk if ur going to see this but how do i make differnet sprites have wall collision, if i copy and paste the scipt it just does this werid glitch.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      What's the weird glitch?

    • @chrismations9191
      @chrismations9191 Před 2 lety

      @@ShiftClickLearn it like slows down the character not completely stopping it, and it makes the character speed faster for some reason

  • @darkplayz9890
    @darkplayz9890 Před rokem +1

    Amazing! First tutorial I could find that isn't janky and weird, and I understood all of it! Great tutorial!

  • @djastrobrando8222
    @djastrobrando8222 Před 2 lety +1

    what a simple way to pull this off I had it all wrong when I tried to do it myself

  • @swimminghq3739
    @swimminghq3739 Před 2 lety +1

    it doesnt work. when my sprite touches a wall, the sprite cant be moved again

  • @DR_Sam_YouTube
    @DR_Sam_YouTube Před 2 lety +2

    it doesn't work i spent so much time the moving keys didn't work let alone the collison

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      Try this one: czcams.com/video/OmRh6SXoI0Y/video.html

  • @bumblebeecontent6816
    @bumblebeecontent6816 Před 3 lety +2

    Keep going, good video

  • @DisBuilder
    @DisBuilder Před 2 lety +2

    Thanks! it worked i made a maze game!

  • @frootloop4686
    @frootloop4686 Před 2 lety +1

    THANK YOU SO MUCH MY CODING PROJECT IS DUE IN A DAY AND I NEEDED THIS

  • @kelfon26
    @kelfon26 Před 2 lety +1

    I went through it a couple times and it did not work for me.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      It should still work! Here's the project: scratch.mit.edu/projects/569868885/

  • @octagonanimates
    @octagonanimates Před 2 lety +2

    Dude this is great! I'll put you in the notes and credits for the tutorial.

  • @MrWilliamag
    @MrWilliamag Před 2 lety +3

    thanks but now how do i push?
    😃

  • @bonard56
    @bonard56 Před 3 lety +4

    Nice vid:D

  • @GuuGuu03
    @GuuGuu03 Před 2 lety +2

    THANK YOU FINALLY

  • @SyedRaheemR
    @SyedRaheemR Před 2 lety +1

    whenever my sprite touches the wall it stop going HOW I FIX

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      Isn't that the point of wall collision?

    • @someoninte456
      @someoninte456 Před 2 lety

      @@ShiftClickLearn I think they mean that they can't move at all after it. I can't.

  • @koxxu1337
    @koxxu1337 Před 2 lety +2

    thank you so much

  • @beluga2738
    @beluga2738 Před 2 lety +3

    Thank you so much! This is gonna help with my platformer

  • @himmenberg
    @himmenberg Před rokem

    gotta love how there is also a scrolling tutorial implemented into this

  • @rasmusvanwerkhoven1962
    @rasmusvanwerkhoven1962 Před 3 lety +3

    Thank you so much, that was extremely helpful and informative!

  • @nagulasankaralingamelango3024

    Thank you so much, man I had a hard time trying to stop the sprite from going through. nice coding!

  • @tinybrain828
    @tinybrain828 Před rokem

    Gees this is incredibly easy to follow

  • @supersisters2181
    @supersisters2181 Před 2 lety +2

    Hello I have a quick question, when my player/ character is touching the wall, it stops moving entirely, all of the code is the exact same, what should I do about that?? (I checked your project btw)

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      Do you have another script that interferes with the wall collision?

  • @daboondaboon
    @daboondaboon Před 7 měsíci

    Amazing, works flawlessly.

  • @down7747
    @down7747 Před 2 lety +1

    Thank you so much I've been trying to figure this out for months!

  • @BlueBloxxerPlayerXD
    @BlueBloxxerPlayerXD Před 3 lety +1

    Thanks for this Tutorial!

  • @coolestgyever531
    @coolestgyever531 Před 2 lety +1

    Hey! Been playing around with scratch as a primer for cs50 and your tutorial came up. I'll be giving this a shot for my game tomorrow thanks!

  • @Spinning.tornado
    @Spinning.tornado Před rokem

    Thx so much im newer to coding so this helped and this is the first time using the define block since i barley know how it works but this video helped me understand it better and learn how to make a good moving script and a way you would not go through walls this will help me with alot of future projects !!!

  • @popcorn3576
    @popcorn3576 Před 2 lety +3

    My brain has expanded

  • @landnpr3414
    @landnpr3414 Před 2 lety +3

    :(
    man this sucks theres a glitch i found.

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety +1

      You could try the much improved updated version: czcams.com/video/OmRh6SXoI0Y/video.html

  • @souze3263
    @souze3263 Před 2 lety +1

    I'm stumped because I copied the code and then double-checked to make sure (with the code from the actual game) and then it still didn't work... My characters controls get inverted when it touches a wall and the character stays in behind the wall and can't get out

  • @unnamedani_mator5621
    @unnamedani_mator5621 Před 2 lety +1

    thanks so much man! you see im trying to make my own game and i just could not find out how to do the wall collisions so thanks. keep up the great work :)

  • @DumbFishes
    @DumbFishes Před 3 lety +2

    I came here more then I asked for

  • @melonsdimensions478
    @melonsdimensions478 Před 2 lety +1

    Great video! it didn't work at first, but it was only because my wall costume was on another sprite while the wall sprite had no costume.

  • @elminehuy
    @elminehuy Před 3 lety +1

    hey thank you very much for the tutorial, now I can improve the movement system of my scratch games and add walls and collisions!!

  • @DefinitivelyJao
    @DefinitivelyJao Před 2 lety +2

    thanks this helped a lot.

  • @tuanminhnguyen6782
    @tuanminhnguyen6782 Před 3 lety +2

    nice

  • @ThatOneUnwantedNoob
    @ThatOneUnwantedNoob Před rokem

    this is the world of me because I always want to make wall collisions!!! thank you sooooo much thank you!!😄😇

  • @milyonfan69321
    @milyonfan69321 Před 9 dny

    this tutorial helped me a ton Thanks ;)

  • @itsgameboyplay
    @itsgameboyplay Před 3 lety +1

    When I press A and D they go left and right but when I press W and S they don't go up and down

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +2

      Maybe you set the wrong key to move up/down. If you can't figure it out, send me a link the project!

  • @djlyon6309
    @djlyon6309 Před 3 lety +2

    excuse me, how would i make a wall push a sprite when the wall is pushing up against the sprite, im making an undertale box collision test, and when the box collapses, the sprite goes through the wall, instead, i want it to push the sprite with it, thanks

    • @ShiftClickLearn
      @ShiftClickLearn  Před 3 lety +2

      Would you please give me the link to the test project! I could help you out that way!

    • @djlyon6309
      @djlyon6309 Před 3 lety +1

      @@ShiftClickLearn sure! Scratch.mit.edu/projects/466514804/

  • @lakmaliliyanage4059
    @lakmaliliyanage4059 Před 3 lety +1

    use the operations block (or) if you want do arrow keys and wasd

  • @michaelpizzasready7063
    @michaelpizzasready7063 Před 2 lety +1

    when I have moved into the wall for a second and go in the opposite direction the player moves toward and through the wall
    I have tried the new tutorial you uploaded but it does the same

    • @ShiftClickLearn
      @ShiftClickLearn  Před 2 lety

      Are you sure you copied all the code correctly? If not, you can check out the final project here: scratch.mit.edu/projects/569868885/

  • @nolimitkaydeni
    @nolimitkaydeni Před rokem +2

    W CZcamsr W video!!!

    • @ShiftClickLearn
      @ShiftClickLearn  Před rokem

      Thank you! :D

    • @nolimitkaydeni
      @nolimitkaydeni Před rokem

      @@ShiftClickLearn you taught me how to do an easy collision code. Your the best

    • @nolimitkaydeni
      @nolimitkaydeni Před rokem

      @@ShiftClickLearn I'm using your collision technique on a DOORS game on scratch!!! I'll send the game link when its finished.

  • @chadgaming1757
    @chadgaming1757 Před rokem +1

    thanks now i can make a horror rpg

  • @GamingCat343
    @GamingCat343 Před rokem +1

    can you make one for mobile platformers?