Discuss Scratch

JaycobCreator
Scratcher
16 posts

How to make collisions?

Well I'm making a platformer game and I'm trying to make collisions in my project. What do I do?
dragonsnake003
Scratcher
100+ posts

How to make collisions?

JaycobCreator wrote:

Well I'm making a platformer game and I'm trying to make collisions in my project. What do I do?
There is some different ways people go about this, but a great way is to make it is by pushing yourself out of a platform repeatedly until you are out of it. Put it in a custom block loop and run it without screen refresh, and it should work fine. Things are pretty easy from there. For a better explanation, see youtube.com/@griffpatch and find his first tutorial on how to code a classic platformer. Hope this helps!
Neometamarcel
Scratcher
1 post

How to make collisions?

I'm making a dark platformer game and I'm confused how to make collisions I tried every video how to make collisions in scratch and that didn't work for me
Seriously how can I make the collisions

Last edited by Neometamarcel (Jan. 2, 2025 04:44:24)

Nerdiesssss
Scratcher
100+ posts

How to make collisions?

dragonsnake003 wrote:

JaycobCreator wrote:

Well I'm making a platformer game and I'm trying to make collisions in my project. What do I do?
There is some different ways people go about this, but a great way is to make it is by pushing yourself out of a platform repeatedly until you are out of it. Put it in a custom block loop and run it without screen refresh, and it should work fine. Things are pretty easy from there. For a better explanation, see youtube.com/@griffpatch and find his first tutorial on how to code a classic platformer. Hope this helps!

whenclickedforeverifkeywpressed?thenchangexby10iftouchingbarrier?thenchangexby-10

Here is an example hope it helps!
DidntMeanToDoThat
Scratcher
500+ posts

How to make collisions?

Let's say you have a sprite, which you want to have collisions with. To start with this method, you will need to make the player change direction depending on which way it's moving. The following code is an example of what the code could be in the player sprite (with WASD controls):
whenclickedforeverifkeyWpressed?thenchangeyby10pointindirection0ifkeyApressed?thenchangexby-10pointindirection-90ifkeySpressed?thenchangeyby-10pointindirection180ifkeyDpressed?thenchangexby10pointindirection90
It's important to note with this method that firstly, if you have a jumping system, when the player character is falling back down you will have to make the sprite face down (180), and second of, if you have a player character that isn't just a ball, then it will of course rotate visually as well when it changes direction. A solution for this is to have an invisible “player guide” sprite that does all the movement, that the main player sprite with all the visuals constantly teleports to. If you need more info and examples, let me know. Next, put this code in the player sprite (this is what will actually do the collisions):
whenclickedforeveriftouchingSprite you want to have collision with?thenrepeatuntilnottouchingSprite you want to have collision with?move-1steps
You can change the number of steps in the
movesteps
block if it's to slow. For example,
move-10steps
would be faster than
move-5steps
If you have any questions, let me know. I haven't done much work with collisions, but this should work.

Last edited by DidntMeanToDoThat (Jan. 2, 2025 06:34:21)

DragonPlusMaster
Scratcher
100+ posts

How to make collisions?

DragonPlusMaster wrote:

I've seen people handle collisions something like this:

whenclickedforevercollision

definecollisioniftouchinghitbox?thengotox:xy:yelsesetxtoroundx positionofmap this is for a scrolling game-if not-make it x position of playersetytoroundy positionofmap same with this one, but y position hitbox could be replaced with wall
This just supplies the code for when you touch the wall, but not the movement code itself. For the movement code, instead of moving two steps, you change the variables x and y appropriately. If this is too confusing, I can help explain a little more clearer.

Last edited by DragonPlusMaster (Jan. 2, 2025 21:25:26)

Mynxus
Scratcher
10 posts

How to make collisions?

DidntMeanToDoThat wrote:

(#5)
Let's say you have a sprite, which you want to have collisions with. To start with this method, you will need to make the player change direction depending on which way it's moving. The following code is an example of what the code could be in the player sprite (with WASD controls):
whenclickedforeverifkeyWpressed?thenchangeyby10pointindirection0ifkeyApressed?thenchangexby-10pointindirection-90ifkeySpressed?thenchangeyby-10pointindirection180ifkeyDpressed?thenchangexby10pointindirection90
It's important to note with this method that firstly, if you have a jumping system, when the player character is falling back down you will have to make the sprite face down (180), and second of, if you have a player character that isn't just a ball, then it will of course rotate visually as well when it changes direction. A solution for this is to have an invisible “player guide” sprite that does all the movement, that the main player sprite with all the visuals constantly teleports to. If you need more info and examples, let me know. Next, put this code in the player sprite (this is what will actually do the collisions):
whenclickedforeveriftouchingSprite you want to have collision with?thenrepeatuntilnottouchingSprite you want to have collision with?move-1steps
You can change the number of steps in the
movesteps
block if it's to slow. For example,
move-10steps
would be faster than
move-5steps
If you have any questions, let me know. I haven't done much work with collisions, but this should work.

DragonPlusMaster wrote:

(#6)

DragonPlusMaster wrote:

I've seen people handle collisions something like this:

whenclickedforevercollision

definecollisioniftouchinghitbox?thengotox:xy:yelsesetxtoroundx positionofmap this is for a scrolling game-if not-make it x position of playersetytoroundy positionofmap same with this one, but y position hitbox could be replaced with wall
This just supplies the code for when you touch the wall, but not the movement code itself. For the movement code, instead of moving two steps, you change the variables x and y appropriately. If this is too confusing, I can help explain a little more clearer.

just by the way, this post is 8 months old.
DragonPlusMaster
Scratcher
100+ posts

How to make collisions?

Mynxus wrote:

just by the way, this post is 8 months old.

Oh oops lol

I see problem. I fix problem. XD
DidntMeanToDoThat
Scratcher
500+ posts

How to make collisions?

DragonPlusMaster wrote:

Mynxus wrote:

just by the way, this post is 8 months old.

Oh oops lol

I see problem. I fix problem. XD
Oh… why was this at the top of help with scripts when I saw it then? Anyways, nice reminder to check dates of posts. Oopsie.

Last edited by DidntMeanToDoThat (Jan. 2, 2025 23:05:21)

DragonPlusMaster
Scratcher
100+ posts

How to make collisions?

DidntMeanToDoThat wrote:

DragonPlusMaster wrote:

Mynxus wrote:

just by the way, this post is 8 months old.

Oh oops lol

I see problem. I fix problem. XD
Oh… why was this at the top of help with scripts when I saw it then? Anyways, nice reminder to check dates of posts. Oopsie.
I don't really think it was solved so at least we're helping lol
DidntMeanToDoThat
Scratcher
500+ posts

How to make collisions?

DragonPlusMaster wrote:

I don't really think it was solved so at least we're helping lol
Yeah, at least if someone stumbles across this while wondering about how to do collisions, they'll get some help. I have seen a lot of people ask about collisions.
SAMSUNGGUY768
Scratcher
1 post

How to make collisions?

definehowmakecollision

Last edited by SAMSUNGGUY768 (April 27, 2025 00:55:50)

Powered by DjangoBB