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
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
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.
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.
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
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?
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
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!!
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.
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
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
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/
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)
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 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?
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
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)
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?
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)
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 !!!
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
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 :)
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
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
I Like how you explain why it works instead of just showing so people learn. This helped alot thanks!
Glad it helped!
Griffpatch exists you know
Thank you so much!I have been struggling for a way to not go through walls.
You are welcome! Glad I could help! 😁
Thanks so much, my teacher gave me code that
1. Teleported my sprite
2. Had the WALLS AS A BACKDROP
Dun dun dunnnnnnnn
Looool! Glad I could help! :P
me too
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
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
Hmm... My project works fine. I wonder is going on!
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
Nevermind i figured it out, when i pressed the left arrow key my character would face -90 degrees making him clip into the wall.
Great! I'm glad you figured it out!
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.
Yeah it was intentional! Thanks! :D
@@ShiftClickLearn its not working
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.
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
everything works,but when it gets to the wall it has a little gap
Hm, maybe try the updated tutorial: czcams.com/video/OmRh6SXoI0Y/video.html
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?
You can check out the code here: scratch.mit.edu/projects/569868885/
@@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
ninja is in the thumbnail
Yup!
Finally a Pro way to make colisions, rpg scrolling and customizable movement speed🎉❤ I like it and I love it❤❤
This is so smooth. I love it. And the movement is great aswell!
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?
They need to have their own for this sprite only x and y variables! :D
@@ShiftClickLearn Ok, do you mean like make new variables called X ad Y? I'm not that good at scratch.
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.
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
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
They are pretty amazing!!
@@ShiftClickLearn yeah , exactly 😂
thank you so much for the explenation at the end! awsome video!
You're very welcome!
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!!
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
Glad I could help!
My games used to all be non-platformers until i found this video
xD
@@ShiftClickLearn XD
Terrific video, thanks Owen! You were super clear and you made sense of a very confusing piece of code. I really appreciated it.
You're very welcome!
your name is...... Owen?
@@venomatic163I was today years old when I found that out!
This is some delicious code. Thank you for helping me make my yummy game.
Glad I could help you to make a scrumptious game!
is this game about fricking cooking or something
@@kaveyalt It’s obviously delicious!
Dude, that was the only video that really helped me do week 0 of cs50.
this was very helpful, thanks
You are welcome!
Thank You! You Just Helped Me For My Game Which Needs Wall Collision!
You are very welcome!
Also, Thank You Not Only For This, But For All UR Helpful Video's, Just Like Griffpatch :)
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.
This shouldn't happen!
Yeah the same thing happened to me,
how do you make it so you can rotate while moving
It the change x by/ y by add a rotate block!
im making a game and im planning big things for it and this helped me so much
I'm glad!
This code is so BEAUTIFULL !
Wow thanks!
Im not used to making blocks and i dont really know how they work so it baffled me when it worked lol xD
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
@@ShiftClickLearn thank you
Thanks so much! This really helped me with my game :)
You are very welcome! Glad to hear that!
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
The same
Do your scripts look like these? scratch.mit.edu/projects/569868885/
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
Maybe try my updated tutorial: czcams.com/video/OmRh6SXoI0Y/video.html
its because your not using a hit box. instead, your using the spirit that moves around.
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
Glad I could help
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/
Thanks
Yes!
Thanks!
oh it did more than helped...
but can you make a video about this too but with move block so i can manage direction
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)
That is really weird.. I checked my code and it still works
It doesn’t work for me for some reason and I’ve tried everything
Try an updated tutorial: czcams.com/video/OmRh6SXoI0Y/video.html
It has much better code! :D
really helpful, even outside scratch the logic still helps
Awesome! :D
I find that the basic logic is similar across many languages!
thanks for the tutorials
You are welcome!
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.
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.
Could you send me a link to your project?
@@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?
Thank you this is the best video and I finally got after hours of research
You are very welcome Vandana singh!
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!
That's awesome! :D
I Can use this for many of my games! Thanks for Making this!
No problem, good luck with your game! :D
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
No problem, glad it helped you out. :D
is there any way to add costume changes to the moving script so i can use a non smooth character
That would require a lot more code...
Tysm!! This helped tremendously with my top-down RPG. I smashed that sub button as hard as I could when the engine worked!
I am glad!!!
hey! really like this tutorial but what if i want to make multiple different sprites be walls? what do i do?
See all the touching walls? Change them to touching wall OR touching wall2 (Or whatever your second wall is named)!
@@ShiftClickLearn Ohh okay! So do i just make a new If box and put it under the already make if touching wall?
@@bido64 no, get the "and" block and put the "touching wall2" block inside the empty space or whatever the name is.
@@ckqk thank you
Wow,many thanks! Im currently working on a adventure game on a huge map so this is extremely important. THanks again!
You're very welcome! I'm glad this helped you out!!
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)
Wow thanks!!! I really like your profile pic!
@@ShiftClickLearn thank you!
Great video, you’re very clever.
Thank you!
Really helpful! Your tutorial does not only help Scratch games but it also helps my Pygame game :D
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.
Hmm
sounds like something is “set x to” instead of “change x by”
This is so goooooooood!!!!! I can finally make a rage game without making people rage! THX!
Thanks!! :D
Simple and useful. Thx
You're welcome!
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?
for some reason, when I click the green flag the game just stops admittedly how do I fix this problem?
Huh...🤔 It's hard to tell without seeing the code. Would you send me a link the project?
Ok
I found the problem but now it wont move when i touch the wall
Here scratch.mit.edu/projects/516480899/
@@HaniwaBun Would you please send me a link to the project?
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.
What's the weird glitch?
@@ShiftClickLearn it like slows down the character not completely stopping it, and it makes the character speed faster for some reason
Amazing! First tutorial I could find that isn't janky and weird, and I understood all of it! Great tutorial!
what a simple way to pull this off I had it all wrong when I tried to do it myself
it doesnt work. when my sprite touches a wall, the sprite cant be moved again
nevermind! i got it to work!!!
Great! :D
it doesn't work i spent so much time the moving keys didn't work let alone the collison
Try this one: czcams.com/video/OmRh6SXoI0Y/video.html
Keep going, good video
Thank you, I will
Thanks! it worked i made a maze game!
You're welcome! That's cool!
THANK YOU SO MUCH MY CODING PROJECT IS DUE IN A DAY AND I NEEDED THIS
YOU ARE SO WELCOME I AM GLAD I COULD HELP :P
I went through it a couple times and it did not work for me.
It should still work! Here's the project: scratch.mit.edu/projects/569868885/
Dude this is great! I'll put you in the notes and credits for the tutorial.
Awesome, glad I could help! :D
@@ShiftClickLearn np :)
thanks but now how do i push?
😃
What do you mean?
Nice vid:D
Thanks! 😁
THANK YOU FINALLY
You are welcome
whenever my sprite touches the wall it stop going HOW I FIX
Isn't that the point of wall collision?
@@ShiftClickLearn I think they mean that they can't move at all after it. I can't.
thank you so much
You're welcome!
Thank you so much! This is gonna help with my platformer
Glad I could help!
gotta love how there is also a scrolling tutorial implemented into this
Thank you so much, that was extremely helpful and informative!
You are welcome! Glad it was helpful!
Thank you so much, man I had a hard time trying to stop the sprite from going through. nice coding!
Glad I could help!
@@ShiftClickLearn :)
Gees this is incredibly easy to follow
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)
Do you have another script that interferes with the wall collision?
Amazing, works flawlessly.
Thank you so much I've been trying to figure this out for months!
You are very welcome!
Thanks for this Tutorial!
You're welcome!
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!
Hey, that's awesome! Good luck! :D
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 !!!
My brain has expanded
wow
:(
man this sucks theres a glitch i found.
You could try the much improved updated version: czcams.com/video/OmRh6SXoI0Y/video.html
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
Hmm... try redoing the code!
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 :)
You are very welcome!
I came here more then I asked for
:D
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.
Hey, thanks! Nice trouble-shooting!
hey thank you very much for the tutorial, now I can improve the movement system of my scratch games and add walls and collisions!!
Glad it helped!
thanks this helped a lot.
You are welcome!
nice
Thanks!
this is the world of me because I always want to make wall collisions!!! thank you sooooo much thank you!!😄😇
this tutorial helped me a ton Thanks ;)
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
Maybe you set the wrong key to move up/down. If you can't figure it out, send me a link the project!
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
Would you please give me the link to the test project! I could help you out that way!
@@ShiftClickLearn sure! Scratch.mit.edu/projects/466514804/
use the operations block (or) if you want do arrow keys and wasd
Thanks!
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
Are you sure you copied all the code correctly? If not, you can check out the final project here: scratch.mit.edu/projects/569868885/
W CZcamsr W video!!!
Thank you! :D
@@ShiftClickLearn you taught me how to do an easy collision code. Your the best
@@ShiftClickLearn I'm using your collision technique on a DOORS game on scratch!!! I'll send the game link when its finished.
thanks now i can make a horror rpg
can you make one for mobile platformers?