Discuss Scratch

EvanTheEevee543
Scratcher
75 posts

Walls collision

in my https://scratch.mit.edu/projects/362911146/ game, you can clip through a wall I set up (Its deleted now), how do I make it have collision
wd4q5dy
Scratcher
100+ posts

Walls collision

You just need:
when green flag clicked
forever
if <touching color [#000000] ?> then
repeat until <not <touching color [#000000] ?>>
change y by (1)
end
end
end
That should work, I think.
EvanTheEevee543
Scratcher
75 posts

Walls collision

wd4q5dy wrote:

You just need:
when green flag clicked
forever
if <touching color [#000000] ?> then
repeat until <not <touching color [#000000] ?>>
change y by (1)
end
end
end
That should work, I think.
It wont, when I try doing that, the player just bobs up and down, and thats for not clipping through the ground, not walls
LordThror
Scratcher
100+ posts

Walls collision

I've seen people do something this

when green flag clicked
forever
if <<touching color [#58c937] ?>> then
change y by (1)
if <<touching color [#58c937] ?>> then
change y by (1)
end
end
end

And then the if-then statement is repeated a lot.
EvanTheEevee543
Scratcher
75 posts

Walls collision

LordThror wrote:

I've seen people do something this

when green flag clicked
forever
if <<touching color [#58c937] ?>> then
change y by (1)
if <<touching color [#58c937] ?>> then
change y by (1)
end
end
end

And then the if-then statement is repeated a lot.
Ugh… It doesn't work! First off, it walls, not ground
Second, its velocity + scrolling
Third: I want a global sprite, not if touching color
SpideyPlaysMC
Scratcher
500+ posts

Walls collision

You might wanna use this instead:
<touching [ground v] ?> //whatever you name the terrain
It works for scrolling.

Last edited by SpideyPlaysMC (Feb. 9, 2020 15:11:01)

Queble
Scratcher
100+ posts

Walls collision

EvanTheEevee543 wrote:

in my https://scratch.mit.edu/projects/362911146/ game, you can clip through a wall I set up (Its deleted now), how do I make it have collision
Just change Ypos by 1, and repeat this process until the player is not touching the ground sprite.
make sure to put it inside a “run without screen refresh” custom block, and fit it into a forever loop.
BlueNoodle29
Scratcher
100+ posts

Walls collision

EvanTheEevee543 wrote:

wd4q5dy wrote:

You just need:
when green flag clicked
forever
if <touching color [#000000] ?> then
repeat until <not <touching color [#000000] ?>>
change y by (1)
end
end
end
That should work, I think.
It wont, when I try doing that, the player just bobs up and down, and thats for not clipping through the ground, not walls


Because it is a wall not ground, change x pos instead of y
EvanTheEevee543
Scratcher
75 posts

Walls collision

Queble wrote:

EvanTheEevee543 wrote:

in my https://scratch.mit.edu/projects/362911146/ game, you can clip through a wall I set up (Its deleted now), how do I make it have collision
Just change Ypos by 1, and repeat this process until the player is not touching the ground sprite.
make sure to put it inside a “run without screen refresh” custom block, and fit it into a forever loop.
As I said, when I try doing that, the player bobs up and down like a piece of kelp in water in minecraft
qucchia
Scratcher
100+ posts

Walls collision

EvanTheEevee543 wrote:

As I said, when I try doing that, the player bobs up and down like a piece of kelp in water in minecraft

You need to put that code inside a custom block, and check the checkbox that is labelled “Run without screen refresh”.
charusing
New Scratcher
9 posts

Walls collision

You can try this:
´
when green flag clicked
forever
set [ x] to (x position)
set [ y] to (y position)
if <<touching [ v] ?> or <touching color [#457126] ?>> then
go to x: (x) y: (y)
end
set [ x] to (x position)
set [ y] to (y position)

This only works on this.

———————————
| you |
| | |
| V |
| |
| |
| |
| |
———————————
Neverdeletescratch
Scratcher
15 posts

Walls collision

if <> then
<touching [Wall v] ?>
move (-5) steps
end
Neverdeletescratch
Scratcher
15 posts

Walls collision

If <Touching > then
Move (-10) steps
queen_slay32
New Scratcher
1 post

Walls collision

these comments don't make sense do it properly!!!!!!!!!!
cool157
Scratcher
41 posts

Walls collision

EvanTheEevee543 wrote:

LordThror wrote:

I've seen people do something this

when green flag clicked
forever
if <<touching color [#58c937] ?>> then
change y by (1)
if <<touching color [#58c937] ?>> then
change y by (1)
end
end
end

And then the if-then statement is repeated a lot.
Ugh… It doesn't work! First off, it walls, not ground
Second, its velocity + scrolling
Third: I want a global sprite, not if touching color

Griffpatch made a video that might help

Last edited by cool157 (May 19, 2023 04:59:27)

gabriel108thedudesss
Scratcher
2 posts

Walls collision

EvanTheEevee543 wrote:

in my https://scratch.mit.edu/projects/362911146/ game, you can clip through a wall I set up (Its deleted now), how do I make it have collision
i must be happy
amogus1123
Scratcher
500+ posts

Walls collision

gabriel108thedudesss wrote:

EvanTheEevee543 wrote:

in my https://scratch.mit.edu/projects/362911146/ game, you can clip through a wall I set up (Its deleted now), how do I make it have collision
i must be happy
don't necropost.
NMario84
Scratcher
1000+ posts

Walls collision

This is how I would typically set up walls.

when green flag clicked
forever
Movement
end

define Movement
// Run without screen refresh [X]
change x by (10) //runs to the right
repeat until <not <touching [wall v]>>
change x by (-1) //pushes the object/player out of the wall until it is no longer against it.
end
Running this without screen refresh should help push out the sprite from against the walls.
As this is just a script for X forward movement running to the right, the same can be applied to Y movement too.

Though maybe your project is handled a bit differently.

———————————————————————————————

EDIT: Oh….. I see…. It's a 5 month old topic bump… Okay then.

Last edited by NMario84 (Oct. 31, 2023 23:54:37)

eggylego
Scratcher
1 post

Walls collision

wd4q5dy wrote:

You just need:
when green flag clicked
forever
if <touching color [#000000] ?> then
repeat until <not <touching color [#000000] ?>>
change y by (1)
end
end
end
That should work, I think.
dose not work for me
S742121
Scratcher
5 posts

Walls collision

EvanTheEevee543 wrote:

LordThror wrote:

I've seen people do something this

when green flag clicked
forever
if <<touching color [#58c937] ?>> then
change y by (1)
if <<touching color [#58c937] ?>> then
change y by (1)
end
end
end

And then the if-then statement is repeated a lot.
Ugh… It doesn't work! First off, it walls, not ground
Second, its velocity + scrolling
Third: I want a global sprite, not if touching color

the colours of the walls can be very slightly different to the ground and the move Y 1 can be changed to move X 1

Powered by DjangoBB