This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-20 17:24:52

Unknown164
Scratcher
Registered: 2012-04-08
Posts: 7

How to make sure a sprite does not go through a wall

I am currently making 2 games, and in both of them there is a huge glitch: you can walk through the walls.
Could someone please put up a script in scratchblocks?

Offline

 

#2 2012-04-20 17:43:17

SOScratch
Scratcher
Registered: 2010-02-01
Posts: 100+

Re: How to make sure a sprite does not go through a wall

OK, here is a script that should work:

when gf clicked
forever
if <touching color [#000000]?> //change this color to the color of the walls
point in direction ( (direction) - (180) )
repeat until <not <touching color [#000000]?> > //change to color of walls
move (1) steps //you may need to make this faster
end
end
end
Tell me if there is any problem with that script or it doesn't work so I can fix it.

Last edited by SOScratch (2012-04-20 17:47:55)


-SOScratch
Scratch On!

Offline

 

#3 2012-04-20 18:29:30

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to make sure a sprite does not go through a wall

The script really depends on whether you're viewing the character from the top or if it is a platformer.  If it is top-down, try looking at this project.  If it is a platformer, the script can vary quite a bit depending on what exactly you want.  Here is  pretty decent platformer-base that I made that should help.  It includes the ability to climb a slant, as well as jumping and walls.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#4 2012-04-20 18:33:28

Yoshi789
Scratcher
Registered: 2011-08-08
Posts: 100+

Re: How to make sure a sprite does not go through a wall

when gf clicked
forever
if < color [#00FF00] is touching [#735D35] ? > //change brown to color of walls
set [XVel v] to ( (0) - (XVel) )
end
if < color [#FFFB00] is touching [#735D35] ? > //same here.
set [XVel v] to < [abs v] of (XVel)>
end
end
Note this is color-based. Green is right side of sprite and yellow is left.

Hope this helps!

Yoshi789

Last edited by Yoshi789 (2012-04-20 18:35:11)

Offline

 

#5 2012-04-21 18:25:41

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: How to make sure a sprite does not go through a wall

You may have to make the walls thicker, if you want too and it doesn't affect the rest of the game. You could also try making xvel smaller (dividing xvelby a greater number).


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

Board footer