Eng:Wall-Jumping

Wall-Jumping is a technique used in Scratch to make sprites bounce off walls. This allows a character in a project, for instance, to scale up massive heights of walls rather than jumping on individualized sections like stairs. It is commonly used in platformers.

Method
This is just one of the ways for wall jumping to work.

Three variables are needed for this method to operate properly:
 * L-vel The velocity of the player going left
 * R-vel The velocity of the player going right
 * Y-vel The velocity of the player on the Y axis

Afterwards, a player sprite should be made. This is the sprite that will perform all motions and be physically wall-jumping. An example of a player sprite is shown below:



The colours on each side of the square are the sensors that will use to "sense" which side the wall and floor are relative to the character. Using more complicated coding, it wouldn't require colours.

Two separate scripts are needed then, one for moving and one for sensing walls:

when gf clicked set [R-vel v] to [0] set [L-vel v] to [0] forever if  then change [R-vel v] by (1) end if  then change [L-vel v] by (1) end if  then if  then set [Y-vel v] to [20] broadcast [Jump v] end end if > then change y by (-5) end if  then set [Y-vel v] to [0] set [R-vel v] to [0] if  or  > > then wait (0.5) secs if  then set [Y-vel v] to [20] broadcast [Jump v] end set [L-vel v] to [10] end end if  then set [Y-vel v] to [0] set [R-vel v] to [0] if  or  > > then wait (0.5) secs if  then set [Y-vel v] to [20] broadcast [Jump v] end set [R-vel v] to [10] end end change x by (R-vel) change x by ((0) - (L-vel)) change [R-vel v] by ((R-vel) * (-0.2)) change [L-vel v] by ((L-vel) * (-0.2))

And one for jumping:

when I receive [Jump v] repeat (10) if  then set [Y-vel v] to [0] stop script end change y by (Y-vel) change [Y-vel v] by (-1) end set [Y-vel v] to [0]

There is another way of doing it. One variable is needed when gf clicked forever if  then change [velocity v] by (-1) end if  then change [velocity v] by (1) end if <not <touching [ground v]>> change y by (-10) end if <key [up arrow v] pressed> change y by (60) end change y by (1) change x by (velocity) if <touching [ground v]> change x by ((0)-(velocity)) if <key [up arrow v] pressed> change y by (60) change x by ((0)-(velocity)) end change y by (-1) set [velocity v] to ((velocity)*(0.75)) end
 * velocity The velocity of the player's horizontal movement.

Examples

 * Wall jump engine (the script that was used for this article)