Character Moving

Jumping & Landing

jumping up only if character on the floor

We have to let the character jump when the up arrow key is pressed. But this must only happen when the character is currently on the floor.

 

Add an <Up> event. We first test whether the position below the character creates a collision...

  • Check Collision: is character on the floor/platform?
    with only solid objects at (0,1), relative
  • Speed Vertical: set to -10

if character is in the air

Now add a Step event...add a Comment action (type in the box "check whether in the air")

If character is in the air, if the position just below character is empty (no solid objects), then set the gravity to a positive number.

  • Check Empty: (0,1), only solid, relative
  • Set Gravity: direction = 270 (=down), gravity = .5 (not relative).
  • Else
  • Set Gravity: direction = 270, gravity = 0 (not relative)

We also want to limit the vertical speed so if it's more than 12, we'll set back to 12. So add a few more actions:

  • Comment - "limit vertical speed"
  • Test Variable: if variable vspeed > 12
  • Speed Vertical: set to 12

Test it out and see that it works. Your character should go up.

  • it'll go up but when falls, it'll fall through the floor (it won't land yet on the platforms - don't worry, that's the next step.)

landing on blocks

In the character object, we have to make sure he lands correctly on the floor (when collides with a block object). We need to place the character back to its previous position just before the collision; if it's already at the current position, it doesn't move.

 

So add the Collision with block event. 

  • Move to Contact: direction = "direction" (indicates the current direction of motion of the object), maximum = "12", against solid objects
  • Speed Vertical: set to 0

Room

In your room, add a couple platforms so you can test it out (note: the character can only jump about 6 grid squares up)