Discuss Scratch

szym73
Scratcher
21 posts

Making a platformer, how to stop sprite from going through walls.

I am making a platformer, and I just can't work out how to stop my sprites from going through walls. I managed to make a working floor and gravity, but that doesn't stop the sprite going through walls.
ask [please help] and wait
latin_gamerX
Scratcher
500+ posts

Making a platformer, how to stop sprite from going through walls.

when green flag clicked
forever
if <([y position v] of [ground sprite v]) > ([y position v] of [player sprite v])> then
set y to (([y position v] of [ground sprite v]) + (1))
end
end
mariokibmib
Scratcher
100+ posts

Making a platformer, how to stop sprite from going through walls.

oh easy just make it so if your touching the sprite its negative movement
szym73
Scratcher
21 posts

Making a platformer, how to stop sprite from going through walls.

mariokibmib wrote:

oh easy just make it so if your touching the sprite its negative movement

I don't think that would work, as the sprite would be trying to walk on the ground sprite, but wouldn't manage to because it would keep getting pushed back because it is standing on the thing that pushes it back. You get it?
szym73
Scratcher
21 posts

Making a platformer, how to stop sprite from going through walls.

latin_gamerX wrote:

when green flag clicked
forever
if <([y position v] of [ground sprite v]) > ([y position v] of [player sprite v])> then
set y to (([y position v] of [ground sprite v]) + (1))
end
end

Thanks, i'll try it.
szym73
Scratcher
21 posts

Making a platformer, how to stop sprite from going through walls.

latin_gamerX wrote:

when green flag clicked
forever
if <([y position v] of [ground sprite v]) > ([y position v] of [player sprite v])> then
set y to (([y position v] of [ground sprite v]) + (1))
end
end

Didn't work
deck26
Scratcher
1000+ posts

Making a platformer, how to stop sprite from going through walls.

Search for ‘platformer tutorial’ and look at the one by @griffpatch_tutor.
szym73
Scratcher
21 posts

Making a platformer, how to stop sprite from going through walls.

deck26 wrote:

Search for ‘platformer tutorial’ and look at the one by @griffpatch_tutor.

ok, so i looked at this, and good idea, but thing is, if i wanted to use this then i would have to use all of the tutorial for this to work. I just want something to be compatible with my platformer. I shared this on an alt account for you guys to look at and determine what would be the best way to do this.

https://scratch.mit.edu/projects/436891797/
GachaN0nsense
Scratcher
500+ posts

Making a platformer, how to stop sprite from going through walls.

szym73 wrote:

I am making a platformer, and I just can't work out how to stop my sprites from going through walls. I managed to make a working floor and gravity, but that doesn't stop the sprite going through walls.
ask [please help] and wait

ok, so heres how you stop it from going through walls, set the walls to 1 colour and do the following:
when green flag clicked
forever
if < touching color [#FFFFF] ?> then
set x to (oldx)
set y to (oldy)

end
Don't forget to describe the variables to move it back when you make it.

Last edited by GachaN0nsense (Oct. 16, 2020 14:15:09)

szym73
Scratcher
21 posts

Making a platformer, how to stop sprite from going through walls.

GachaN0nsense wrote:

szym73 wrote:

I am making a platformer, and I just can't work out how to stop my sprites from going through walls. I managed to make a working floor and gravity, but that doesn't stop the sprite going through walls.
ask [please help] and wait

ok, so heres how you stop it from going through walls, set the walls to 1 colour and do the following:
when green flag clicked
forever
if < touching color [#FFFFF] ?> then
set x to (oldx)
set y to (oldy)

end
Don't forget to describe the variables to move it back when you make it.

What if the walls are the same colour as the ground? Meh. I'll try it anyway.

Last edited by szym73 (Oct. 16, 2020 15:18:57)

szym73
Scratcher
21 posts

Making a platformer, how to stop sprite from going through walls.

Its ok now! Thanks for all the help, even if it didn't work.

Powered by DjangoBB