Discuss Scratch

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?
AmFaiq
Scratcher
33 posts

How to make collisions

I am making a rpg
Yusei-Fudo
Scratcher
1000+ posts

How to make collisions

AmFaiq wrote:

I am making a rpg
Need more information than this.
JL2magill
Scratcher
20 posts

How to make collisions

AmFaiq wrote:

I am making a rpg
For what?
when green flag clicked
set [RPG power v] to [1000000000000000000000000000000000000000000000000000000000000000]
Lirey
Scratcher
100+ posts

How to make collisions

AmFaiq wrote:

How to make collision???
set [ dont know] to [1]
If it's from a Birdseye's view (Like the very old Pokémon games) you usually add a script like this:
if <touching [ Object] ?> then
move (The amount you moved forwards but with a - in front) steps
end
But 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:
if <key [ w] pressed?> then
change y by (The amount you want)
if <touching [ Object] ?> then
change y by (the amount you want but negative)
end
end
And for the s key you would input the opposite:
if <key [ s] pressed?> then
change y by (the amount you want but negative)
if <touching [ Object] ?> then
change y by (The amount you want)
end
end
For 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)

Last edited by Lirey (Aug. 1, 2021 23:44:44)

AmFaiq
Scratcher
33 posts

How to make collisions

Thanks
NebulaGamingYT
Scratcher
1 post

How to make collisions

a
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.

Powered by DjangoBB