I made a game with the character moves to the door to gain points. On some harder levels, there is a wall to make it more difficult. The problem is that the character will just walk right through the wall. Any way to fix it?
Last edited by fg123 (2009-06-03 18:55:34)
Offline
If your character is moving to the right into the wall, do this.
<when green flag clicked>
<forever>
<if><touching[The wall]<< <and> >><key[ Right Arrow ]pressed?>
<change x by(-However many steps your sprite is moving.)
Offline
I like this method:
Non-rotating sprites
http://scratch.mit.edu/projects/Paddle2SeeFixIt/188825
Rotating sprites
http://scratch.mit.edu/projects/Paddle2SeeFixIt/188807
Offline
One of my favorite solutions to this problem is to have a sort of box made of sensor sprites that surrounds the character at all times. Then, when the sensor in front of the sprite ("right sensor") comes in contact with a wall, it can set a variable that will prevent the sprite from moving. This works well because it prevents the user from having to back a sprite out of a corner as you would a car. It can work with all four sensors ("top", "bottom", "left") and you can vary the dynamics of how the sprite reacts when its sensors hit an obstacle. Personally, I like to make my sprites "bounce" off of the wall by throwing them backwards a few steps. Not only does it give a bit of realism if not overdone, but it prevents sprites from accidentally slipping through walls, which I find occurs when lots of scripts are running.
Last edited by fullmoon (2009-06-04 13:05:10)
Offline