Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make collisions
- AmFaiq
-
Scratcher
33 posts
How to make collisions
How to make collision???

set [ dont know] to [1]
Last edited by AmFaiq (July 31, 2021 12:18:07)
- Dankiel_
-
Scratcher
100+ posts
How to make collisions
Of what type? are you making a platformer? top down?
- Yusei-Fudo
-
Scratcher
1000+ posts
How to make collisions
I am making a rpgNeed more information than this.
- JL2magill
-
Scratcher
20 posts
How to make collisions
I am making a rpgFor what?
when green flag clicked
set [RPG power v] to [1000000000000000000000000000000000000000000000000000000000000000]

- Lirey
-
Scratcher
100+ posts
How to make collisions
How to make collision???If it's from a Birdseye's view (Like the very old Pokémon games) you usually add a script like this:set [ dont know] to [1]
if <touching [ Object] ?> thenBut that can get tricky as you would always want the character to point in the direction as the object. So to avoid messing with rotation I usually create these for the movements:
move (The amount you moved forwards but with a - in front) steps
end
if <key [ w] pressed?> thenAnd for the s key you would input the opposite:
change y by (The amount you want)
if <touching [ Object] ?> then
change y by (the amount you want but negative)
end
end
if <key [ s] pressed?> thenFor the A key you would do the same code as the S key except turn the Change Ys into Change Xs. For the D key you would do the same code as the W key except change the Change Ys code into Change Xs. Hope this helped, and sorry for any confusion! (Editing note: When making something negative add a - sign in front of the number)
change y by (the amount you want but negative)
if <touching [ Object] ?> then
change y by (The amount you want)
end
end
Last edited by Lirey (Aug. 1, 2021 23:44:44)
- BettaBubbles20
-
Scratcher
40 posts
How to make collisions
Here is a simple collision engine.
when [d v] key pressed
set [old x v] to (x position)
set [old y v] to (y position)
change x by (10)
if <touching [wall v] ?> then
go to x: (old x) y: (old y)
end
when [a v] key pressed
set [old x v] to (x position)
set [old y v] to (y position)
change x by (-10)
if <touching [wall v] ?> then
go to x: (old x) y: (old y)
when [w v] key pressed
set [old x v] to (x position)
set [old y v] to (y position)
change y by (10)
if <touching [wall v] ?> then
go to x: (old x) y: (old y)
when [s v] key pressed
set [old x v] to (x position)
set [old y v] to (y position)
change y by (-10)
if <touching [wall v] ?> then
go to x: (old x) y: (old y)
Like this? Visit my profile at @BettaBubbles20 to find lots of amazing games.
- Discussion Forums
- » Help with Scripts
-
» How to make collisions






