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

#1 2012-07-21 22:23:47

WoopAhhh
New Scratcher
Registered: 2012-07-19
Posts: 19

How to make areas in games unwalkable?

I'm making a game where the player can walk around using the arrow keys, but there are areas I don't want it to be able to walk over, such as lakes, trees, tables, etc

Offline

 

#2 2012-07-21 22:36:31

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How to make areas in games unwalkable?

You could set up the unwalkable areas as a separate sprite, and then have the character return to it's last non-touching spot whenever it touches the unwalkable sprite.  Something similar to this

http://scratch.mit.edu/projects/Paddle2SeeFixIt/188825


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2012-07-21 22:48:11

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

Re: How to make areas in games unwalkable?

Or, alternatively:

when gf clicked
forever
if<key [up arrow v] pressed?>
change y by (2)
if<touching [unwalkable area v]?>
change y by (-2)
end
end
if<key [down arrow v] pressed?>
change y by (-2)
if<touching [unwalkable area v]?>
change y by (2)
end
end
if<key [right arrow v] pressed?>
change x by (2)
if<touching [unwalkable area v]?>
change x by (-2)
end
end
if<key [left arrow v] pressed?>
change x by (-2)
if<touching [unwalkable area v]?>
change x by (2)
end
end


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

Offline

 

#4 2012-07-21 23:05:33

WoopAhhh
New Scratcher
Registered: 2012-07-19
Posts: 19

Re: How to make areas in games unwalkable?

Paddle2See wrote:

You could set up the unwalkable areas as a separate sprite, and then have the character return to it's last non-touching spot whenever it touches the unwalkable sprite.  Something similar to this

http://scratch.mit.edu/projects/Paddle2SeeFixIt/188825

Thank you so much!

Offline

 

#5 2012-07-21 23:10:23

WoopAhhh
New Scratcher
Registered: 2012-07-19
Posts: 19

Re: How to make areas in games unwalkable?

MoreGamesNow wrote:

Or, alternatively:

when gf clicked
forever
if<key [up arrow v] pressed?>
change y by (2)
if<touching [unwalkable area v]?>
change y by (-2)
end
end
if<key [down arrow v] pressed?>
change y by (-2)
if<touching [unwalkable area v]?>
change y by (2)
end
end
if<key [right arrow v] pressed?>
change x by (2)
if<touching [unwalkable area v]?>
change x by (-2)
end
end
if<key [left arrow v] pressed?>
change x by (-2)
if<touching [unwalkable area v]?>
change x by (2)
end
end

Thank you! I'll try it

Offline

 

#6 2012-07-21 23:19:46

WoopAhhh
New Scratcher
Registered: 2012-07-19
Posts: 19

Re: How to make areas in games unwalkable?

Paddle2See wrote:

You could set up the unwalkable areas as a separate sprite, and then have the character return to it's last non-touching spot whenever it touches the unwalkable sprite.  Something similar to this

http://scratch.mit.edu/projects/Paddle2SeeFixIt/188825

You just helped me in\mprove my game so much; thank youuu

Offline

 

#7 2012-07-21 23:32:22

WoopAhhh
New Scratcher
Registered: 2012-07-19
Posts: 19

Re: How to make areas in games unwalkable?

WoopAhhh wrote:

MoreGamesNow wrote:

Or, alternatively:

when gf clicked
forever
if<key [up arrow v] pressed?>
change y by (2)
if<touching [unwalkable area v]?>
change y by (-2)
end
end
if<key [down arrow v] pressed?>
change y by (-2)
if<touching [unwalkable area v]?>
change y by (2)
end
end
if<key [right arrow v] pressed?>
change x by (2)
if<touching [unwalkable area v]?>
change x by (-2)
end
end
if<key [left arrow v] pressed?>
change x by (-2)
if<touching [unwalkable area v]?>
change x by (2)
end
end

Thank you! I'll try it

Worked awesomeley!

Offline

 

#8 2012-07-23 15:02:09

dogsandmariolover
Scratcher
Registered: 2011-11-30
Posts: 14

Re: How to make areas in games unwalkable?

mabye make the area a certian coulor, then do

when gf clicked forever if touching coulor blue turn 180 degrees move 1 steps 
? help!

Last edited by dogsandmariolover (2012-07-23 15:02:33)

Offline

 

#9 2012-07-23 15:06:26

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: How to make areas in games unwalkable?

dogsandmariolover wrote:

mabye make the area a certian coulor, then do

when gf clicked
forever if <touching color [#0D00FF]?>
turn cw (180) degrees
move (1) steps
? help!

That's a very bad way to do it, as it flips the sprite and involved direction (Am I the only one who dislikes it?)


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#10 2012-07-23 20:36:48

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

Re: How to make areas in games unwalkable?

zammer990 wrote:

dogsandmariolover wrote:

mabye make the area a certian coulor, then do

when gf clicked
forever if <touching color [#0D00FF]?>
turn cw (180) degrees
move (1) steps
? help!

That's a very bad way to do it, as it flips the sprite and involved direction (Am I the only one who dislikes it?)

I dislike it because it prevents all movement rather than solely movement along a single axis.  If I move right 1 and down 1, and there is a wall beneath me, I still expect to be moved right by 1.  There are ways to accommodate this, but all of them are more complex (or less easily understood) than traditional 2-dimensional movement.


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

Offline

 

Board footer