• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows How to implement movement of the player object in a room with physics?

  • Thread starter Dmitri Pisarenko
  • Start date
D

Dmitri Pisarenko

Guest
Hello!

I have a room in which the player object is falling from top to bottom. I want the user to be able to move the player object to right and left during its fall.

For this purpose, I created the event handler "Key up - left arrow key" and put the following code into it:

physics_apply_local_force(0, 0, -50,0);

But when I start the game, I see the player object falling, but no horizontal movement, when I press and release the left arrow key.

What can I try in order to be able to move the player object left and right as it falls?

Thanks in advance
 
E

Edwin

Guest
Try phy_position_x and phy_position_y functions to use XY axis. For example:
Code:
if (right_key) {
    phy_position_x += 5;
} else
if (left_key) {
    phy_position_x -= 5;
}
For jumping use phy_linear_velocity_y function:
Code:
if (jump_key) {
   if (physics_test_overlap(x, y+1, 0, objsolid)) {
       phy_linear_velocity_y = -20;
   }
}
 
Last edited:
Top