Can we use the keyboard for the character movements?

  • #20, by AkcayKaraazmakWednesday, 07. October 2015, 15:36 9 years ago
    @Cross, I didnt understand how to use this matesmile Where we should create that action and this code is just for S key?

    Great Poster

    440 Posts


  • #21, by afrlmeWednesday, 07. October 2015, 15:54 9 years ago
    He's talking about the key actions tab found under game category. WASD key movement.

    You don't actually have to create a loop as regular key actions automatically loop while you are pressing the key down. To regulate how often it loops you should add a pause action part to the end of the action list.

    Create an execute a script action for each key you want to use for controlling the movement & include these lines...

    south...
    game.CurrentCharacter.Destination = { x = game.CurrentCharacter.Position.x, y = (game.CurrentCharacter.Position.y + 20) }
    

    north...
    game.CurrentCharacter.Destination = { x = game.CurrentCharacter.Position.x, y = (game.CurrentCharacter.Position.y +
    - 20) }
    

    east...
    game.CurrentCharacter.Destination = { x = (game.CurrentCharacter.Position.x + 20), y = game.CurrentCharacter.Position.y }
    

    west...
    game.CurrentCharacter.Destination = { x = (game.CurrentCharacter.Position.x - 20), y = game.CurrentCharacter.Position.y }
    


    You may want to add a small pause action part after the execute a script action to prevent the engine from looping the actions too quickly. Say 50ms or something.

    You may also want to come up with some method of determining if more than one key is pressed or for if you want to allow diagonal movement.

    Imperator

    7278 Posts

  • #22, by AkcayKaraazmakWednesday, 07. October 2015, 16:00 9 years ago
    Thank you Lee, I will try this.

    Great Poster

    440 Posts

  • #23, by tristan-kangWednesday, 07. October 2015, 17:31 9 years ago
    So if I want to play animation then...

    Play animation "character move - left" (no check wait before animation complete)
    Execute script - game.CurrentCharacter.Destination = { a = (game.CurrentCharacter.Position.x - 20), y = game.CurrentCharacter.Position.y }
    pause xxx ms (based on animation length)
    


    It will be right?

    Great Poster

    267 Posts

  • #24, by afrlmeWednesday, 07. October 2015, 18:23 9 years ago
    eh?

    game.CurrentCharacter.Destination is what is set each time you left click on a scene to make the character move to a new position or object.

    So simply updating the destination values means the table is no longer empty & will change the character to the walk animations automatically.

    Inside of a key (released) version of the key events you should include a stop character action part to cancel the characters movement.

    Imperator

    7278 Posts

  • #25, by tristan-kangWednesday, 07. October 2015, 19:06 9 years ago
    I tried it and it worked. Holding WASD button makes the character move infinitely just like most games did. But when you first hold WASD button the characters stops once and it didn't move smoothly.

    Great Poster

    267 Posts

  • #26, by afrlmeWednesday, 07. October 2015, 19:17 9 years ago
    It's probably down to the movement value specified. The lower the value the less chance you give the engine enough time to loop before updating the destination values before they end up empty. When a character reaches it's destination it will automatically trigger the stop character event.

    Imperator

    7278 Posts

  • #27, by tristan-kangWednesday, 07. October 2015, 19:24 9 years ago
    But when I downed the value the character's moving animation stops at the middle of process. 20 is ideal.

    Great Poster

    267 Posts

  • #28, by afrlmeWednesday, 07. October 2015, 21:07 9 years ago
    I said the lower the value the less likely it is to work, but the higher the value the more chance you have of your character falling short of the way borders.

    Imperator

    7278 Posts

  • #29, by tristan-kangWednesday, 07. October 2015, 21:12 9 years ago
    Damn how I omitted that part. roll I'm still suck at English...

    So I increased the value up to 250 and it works perfectly. I wonder Akcay did this magic too.

    Great Poster

    267 Posts

  • #30, by AkcayKaraazmakThursday, 08. October 2015, 10:23 9 years ago
    Ovv it really worked mate and character doesnt pass the borders???

    Great Poster

    440 Posts