0 Favourites

How do I make a player move by an event

  • Hi!

    I'm struggling with this: I'm creating a game where we use drag and drop to put commands in order, then, we read the commands and execute them, making the player move forward, backward and jump , for example.

    I tried using a while loop and a 'simulate control' to the right, simulating that I was pressing the button, when I read the 'command' "move right" but it doesn't work! The game just stop working and the player don't even move.

    Do you know any way to solve this?

    Thanks.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Hi!

    I'm struggling with this: I'm creating a game where we use drag and drop to put commands in order, then, we read the commands and execute them, making the player move forward, backward and jump , for example.

    I tried using a while loop and a 'simulate control' to the right, simulating that I was pressing the button, when I read the 'command' "move right" but it doesn't work! The game just stop working and the player don't even move.

    Do you know any way to solve this?

    Thanks.

    The moment you mention "While loop" and game stops working, its most likely because it goes into an endless loop . So my advice is to double check that the while is actually working correctly.

  • Don't use while loop for that case. 'While' loop execute the command consecutively so fast as the condition remains true. If it can't find an exit condition, the game will crash.

  • Yes.

    But do you know another way to do this?

  • For how long you want to move the player ?

    This might be a solution :

    Add these boolean instance variables to your player: movingRight, movingLeft, ...etc

    then do, for example: when command = right then Player.movingRight = right.

    then to move the player you test the boolean variables:

    if(Player.movingRight) then :

    • simulate right
    • wait 1s
    • simulate stop
  • I tried this and it worked!

    But I still have no animation and when I call use the command more than one time it only work one time.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)