Jetpack Joyride style flying

The player is constantly moving horizontally. How do i make him go up when space is pressed and down when space is not pressed.

1 Like

Depends on how you are moving the player.

If you do it by increasing the X position of the player, then create a variable (say named yForce). Set yForce to -10 if space is pressed, and 10 if space isn’t pressed. When you update the X position of the player, also update the Y position by adding the value of the variable yForce.

However, you will get a more realistic movement if you use the Physics 2 behaviour. Apply a permanent force along the X axis for horizontal movement (use 0 degrees). Apply a instant force upwards (use -90 degrees) when space is pressed to go up. No need to worry about space not being pressed, as gravity will kick in and drop the player.

1 Like

Platformer character Behavior with less gravity
Key pressed condition + “Allow jumping again” action