I've been working on a platform project recently and have never got this seemingly simple aspect to work properly:
when gf clicked forever if <touching colour>? move (-10) stepsThe problem is, if the sprite is facing the wrong direction,he'll go flying through the wall instead-which defeats the purpose of a wall.
Offline
One way to solve it:
If the wall is to the right of the character
when gf clicked forever if <<key [key to make the sprite go right v] pressed ?> and <touching color [] ?>> change x by [-10]If the wall is to the left of the character
when gf clicked forever if <<key [key to make the sprite go left v] pressed ?> and <touching color [] ?>> change x by [10]
Last edited by Targethero (2012-02-17 12:19:29)
Offline
Yeah, using that script is the common method.
Another way, is to use sensors (basically another sprites which checks if it's touching a color then acts accordingly) to check if moving in that direction is possible.
The Sensor Sprite would look like this:
when gf clicked set [ghost v] effect to (100) set [can_move_up v] to (1) set [can_move_down v] to (1) set [can_move_left v] to (1) set [can_move_right v] to (1) forever go to [Character v] if <color [#FF0000] is touching [#000000]?> set [can_move_up v] to (0) else set [can_move_up v] to (1) end if <color [#00FF00] is touching [#000000]?> set [can_move_down v] to (0) else set [can_move_down v] to (1) end if <color [#0000FF] is touching [#000000]?> set [can_move_left v] to (0) else set [can_move_left v] to (1) end if <color [#FFFF00] is touching [#000000]?> set [can_move_right v] to (0) else set [can_move_right v] to (1) endThen the Character sprite:
when gf clicked forever if <<key [Up Arrow v] pressed?> and <(can_move_up) = (1)>> change y by (4) end if <<key [Down Arrow v] pressed?> and <(can_move_down) = (1)>> change y by (-4) end if <<key [Left Arrow v] pressed?> and <(can_move_left) = (1)>> change x by (-4) end if <<key [Right Arrow v] pressed?> and <(can_move_right) = (1)>> change x by (4) endEdit: Updated sensor sprite costume since the old one broke.
Last edited by Magnie (2012-10-26 12:22:53)
Offline
@Magnie - You might want to mention that the sensor sprite is set to 100% ghost so that it can still sense...but is invisible. It is also then usually chained to the character sprite with a forever loop and a Goto
when gf clicked set [ghost v] effect to (100) forever goto [character_sprite v] end
Offline
Paddle2See wrote:
@Magnie - You might want to mention that the sensor sprite is set to 100% ghost so that it can still sense...but is invisible. It is also then usually chained to the character sprite with a forever loop and a Goto
when gf clicked set [ghost v] effect to (100) forever goto [character_sprite v] end
Yeah, no worries, I had already added it to the script.
Offline
Thank you all;it works much better now!
Offline
Consider trying...
when gf clicked forever if <key [right arrow v] pressed?> change [xvel v] by (1) end if <key [left arrow v] pressed?> change [xvel v] by (-1) end set [xvel v] to ((xvel) * (.87)) change x by (xvel) if <touching [level v]?> change y by (([abs v] of (xvel)) + (1)) if <touching [level v]?> change y by ((0) - (([abs v] of (xvel)) + (1))) change x by ((0)-(xvel)) set [xvel v] to ((xvel) / (2)) end end if <key [up arrow v] pressed?> change y by (-1) if <touching [level v]?> set [yvel v] to (10) end change y by (1) end if <(yvel) < [3]> change y by (-1) if <not<touching [level v]?>> change [yvel v] by (-1) end change y by (1) end set [yvel v] to ((yvel) * (0.9)) change y by (yvel) if <touching [level v]?> change y by ((0) - (yvel)) set [yvel v] to ((yvel) / (2.5)) end end
Offline
wow nice
___________________________________________________________________________________
check this out http://scratch.mit.edu/forums/viewtopic.php?pid=1340669#p1340669
our thread
Offline
I find this thread EXTREMELY helpful! Thank you.
Offline
The Jumping sprite the sensor can tell if the block is right above it or not. So here is a scenario that i am having trouble with. I press the jump button(w) and the sensor sprite does not see any blocks above it, and there aren't so it jumps. But, if the block is a little ways above the sensor sprite, the sensor wont see it so it thinks it clear. Then the sprite jumps and goes through the block above it. How do you make it so, it will still jump, but when it hits something it will bounce back down instead of go through it? Here is the project that I'm making that I'm have this problem with if you want to actually see it for your self http://beta.scratch.mit.edu/projects/10093309/
Thanks,
~Jinx,
Last edited by Jinx98_test (2013-03-27 16:58:19)
Offline