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

#1 2010-02-26 08:41:35

ttmario
Scratcher
Registered: 2009-09-30
Posts: 9

How to make a player stop when it hits a wall in a maze game ?

Please help.

Offline

 

#2 2010-02-26 11:12:54

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Offline

 

#3 2010-02-26 12:53:50

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

Re: How to make a player stop when it hits a wall in a maze game ?

rdococ wrote:

No help from me.

OT: I like your username.

Please keep the posts on topic...and if you can't help personally, maybe you can recommend somebody else who can  smile

To keep players from going through walls, there are a number of different techniques used.  I've seen some that have separate tests for each direction and reverse the move if the player is touching a wall.  Something like this...

[blocks]
<when green flag clicked>
<forever>
<if><key[ Right Arrow  ]pressed?>
<point in direction( 90
<move( 5 )steps>
  <if><touching color[ black
    <move( -5 )steps>
  <end>
<end>
<if><key[ Left Arrow  ]pressed?>
<point in direction( -90
<move( 5 )steps>
  <if><touching color[ black
    <move( -5 )steps>
  <end>
<end>

--- Similar blocks here for Up and Down ---

<end>
[/blocks]

A technique I like uses a couple of variables to remember where the last position that wasn't touching a wall was and returns to that whenever the wall is touched.  You can see that here

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

hope that helps!


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

Offline

 

#4 2010-02-26 22:54:35

ttmario
Scratcher
Registered: 2009-09-30
Posts: 9

Re: How to make a player stop when it hits a wall in a maze game ?

Thank you  smile

Offline

 

#5 2010-02-26 23:18:39

Dazachi
Retired Community Moderator
Registered: 2009-09-12
Posts: 1000+

Re: How to make a player stop when it hits a wall in a maze game ?

Paddle2See wrote:

rdococ wrote:

No help from me.

OT: I like your username.

Please keep the posts on topic...and if you can't help personally, maybe you can recommend somebody else who can  smile

To keep players from going through walls, there are a number of different techniques used.  I've seen some that have separate tests for each direction and reverse the move if the player is touching a wall.  Something like this...

[blocks]
<when green flag clicked>
<forever>
<if><key[ Right Arrow  ]pressed?>
<point in direction( 90
<move( 5 )steps>
  <if><touching color[ black
    <move( -5 )steps>
  <end>
<end>
<if><key[ Left Arrow  ]pressed?>
<point in direction( -90
<move( 5 )steps>
  <if><touching color[ black
    <move( -5 )steps>
  <end>
<end>

--- Similar blocks here for Up and Down ---

<end>
[/blocks]

A technique I like uses a couple of variables to remember where the last position that wasn't touching a wall was and returns to that whenever the wall is touched.  You can see that here

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

hope that helps!

That should work.


Dazachi, Retired Community Moderator
May also know me as OJACheung.

Offline

 

Board footer