Discuss Scratch

-Valtren-
Scratcher
1000+ posts

How to make a collision script for this?

edit: I simplified my script a bit so that you guys can hopefully understand it a bit better.

I've been making a game, and in it it uses this script for movement:

foreverifkeyup arrowpressed?thenchangeyby1ifkeydown arrowpressed?thenchangeyby-1ifkeyright arrowpressed?thenchangexby1ifkeyleft arrowpressed?thenchangexby-1setxtox*0.9setytoy*0.9changexbyxchangeybyy
I've tried various different methods for making collisions but none of them work. Is there any way?

Last edited by -Valtren- (Feb. 22, 2024 01:13:06)

evantparkes
Scratcher
98 posts

How to make a collision script for this?

Would touching blocks work?
ifkey wpressed?thenyourpreviousscriptiftouchingedge?thenreplaceitemoflistwiththing

Last edited by evantparkes (Feb. 21, 2024 16:24:56)

malicondii
Scratcher
100+ posts

How to make a collision script for this?

-Valtren- wrote:

I've been making a game, and in it it uses this script for movement:



(the variables X and Y act as normal X and Y position variables.)
I've tried various different methods for making collisions but none of them work. Is there any way?
as cube upload is blocked for me and i can't see the image, can you share the code in a project so i can see what it is and help better?
evantparkes
Scratcher
98 posts

How to make a collision script for this?

Then if you use D and hit a wall try w it won't work. I'm stumped. Try Youtube
sashimiricedev
Scratcher
100+ posts

How to make a collision script for this?

Try this: https://scratch.mit.edu/projects/927729774
Or this: https://scratch.mit.edu/projects/940310732

Both of these are projects from my Forum Post Demos studio. Check it out!
-Valtren-
Scratcher
1000+ posts

How to make a collision script for this?

-Valtren- wrote:

(#1)
edit: I simplified my script a bit so that you guys can hopefully understand it a bit better.

I've been making a game, and in it it uses this script for movement:

foreverifkeyup arrowpressed?thenchangeyby1ifkeydown arrowpressed?thenchangeyby-1ifkeyright arrowpressed?thenchangexby1ifkeyleft arrowpressed?thenchangexby-1setxtox*0.9setytoy*0.9changexbyxchangeybyy
I've tried various different methods for making collisions but none of them work. Is there any way?
edited the script so it's a bit easier to understand.
sashimiricedev
Scratcher
100+ posts

How to make a collision script for this?

This should help with your problem.
yadayadayadagoodbye
Scratcher
1000+ posts

How to make a collision script for this?

I assume you're tryna make something topdown? If so, you could take a look at this
sashimiricedev
Scratcher
100+ posts

How to make a collision script for this?

Use this
NIKI-KOLCHAGOV
Scratcher
500+ posts

How to make a collision script for this?

The way i make collisions is when the character touches a wall it stops it from moving and waits until the player presses another key
Heres an example this should be in the player sprite
whenclickedforeverifkeywpressed?andnotStopWmovement=1thenmovescript
And in the walls sprite
whenclickedforeveriftouchingPlayer sprite?thensetStop W movementto1waituntilnotkeywpressed?setStop W movementto0
swiftycoder101
Scratcher
2 posts

How to make a collision script for this?

-0

Powered by DjangoBB