How do I undo movement of my player ?

0 favourites
  • 7 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I make a top down puzzle game.

    And i will like to make an undo system like BABA IS YOU.

    when pressing a key, back to last step / grid position.

    Thanks !

  • Use an array to store a history of moves.

    Every time a move is made, push the action/result into the array. When undoing, do the opposite of the last action, and delete it from the array.

  • Use an array to store a history of moves.

    Every time a move is made, push the action/result into the array. When undoing, do the opposite of the last action, and delete it from the array.

    I never used array.

    Can you make me an example please? Thanks!

    i want that my player undo, but even his actions. If he pushes a box, i want to undo too.

    cant understand " do the oposite of the last action " how to do that ?

  • Well the opposite of the last action depends on how you have your actions set up, which I do not know.

    You could also keep track of the locations that an object has been to instead, and use those to move instead.

    Each object can have its own history. So when you use undo just do it for each object based on it's own history, and keep track even if it didn't move.

    I can put an example together later.

    Edit: dropbox.com/s/1vi6kp5p7lcn30n/undo_example.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well the opposite of the last action depends on how you have your actions set up, which I do not know.

    You could also keep track of the locations that an object has been to instead, and use those to move instead.

    Each object can have its own history. So when you use undo just do it for each object based on it's own history, and keep track even if it didn't move.

    I can put an example together later.

    Edit: dropbox.com/s/1vi6kp5p7lcn30n/undo_example.c3p

    Thanks a lot !

  • Well the opposite of the last action depends on how you have your actions set up, which I do not know.

    You could also keep track of the locations that an object has been to instead, and use those to move instead.

    Each object can have its own history. So when you use undo just do it for each object based on it's own history, and keep track even if it didn't move.

    I can put an example together later.

    Edit: dropbox.com/s/1vi6kp5p7lcn30n/undo_example.c3p

    It works ! but when you are at the initial position, players go to x.0 y.0. How can i avoid to do that ? if you spam Undo.

    Or the player and objects delete itself

  • It works ! but when you are at the initial position, players go to x.0 y.0. How can i avoid to do that ? if you spam Undo.

    I do not understand what you mean by this. If there is no history (History X size = 0), then the undo event will not run for that object.

    Or the player and objects delete itself

    As I mentioned in the comments, don't delete the object if you want to preserve it's history. If you delete the object, the history array will no longer have an object associated with it. Just move it off screen, make it invisible, or otherwise disable it.

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