Keyboard Walking

Started by Artilleryman37, Fri 11/02/2011 13:27:33

Previous topic - Next topic

Artilleryman37

hi,

I have been able to get my character to walk with animation via the a(left) and d(right) buttons with:

global script:
function on_key_press(eKeyCode keycode)
{
  if (IsGamePaused()) keycode = 0; // game paused, so don't react to keypresses
 
  if (keycode == eKeyA) moveleft();
  if (keycode == eKeyD) moveright();

seperate script:
function moveleft() {
 
  cCharacter.Walk(cCharacter.x - 20, cCharacter.y, eNoBlock, eWalkableAreas);
 
  }
 
  function moveright() {
 
  cCharacter.Walk(cCharacter.x + 20, cCharacter.y, eNoBlock, eWalkableAreas);
 
  }


The problem im having is if the player tries to use the button again too early or holds the button for continuous movement it interupts the previous walk cycle causing the player to either "elastic band" back to their original position, move in small jerky movements, or just stand in one spot cycling through the walk cycle until you let go of the button.

zabnat

That really isn't a good way to do this. You should really consider using the keyboard movement module (someone will soon jump in to provide a link).

What you would want to do is check keyboard state in repeatedly execute and then animate and move the character "manually". You also need to check for walkable areas manually.

Khris

The default game already includes a Keyboard module which should already move the character using the cursor keys.
You can change that to WASD by editing the module code or set the mode to pressing by changing the line in game_start in Global.asc.
Tapping = tap key to start/stop player, pressing = hold key down to move player

Alternatively may I suggest the module I coded yesterday: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=42843.0

If you decide to use it, I'll look forward to comments and suggestions :)

Artilleryman37

thanks for the replies.

its been a long time since i used ags and ive never used it very indepth.
getting back into it has had a steep learning curve.

i was aware that ags had keyboard movement support but wasnt sure how to implement it, having said that i tried out that module khris wrote and at first glace appears to be just what i was after.

ill have a play around with it in a while to see how it goes but it seems to be good for my use (sprint will be a handy feature i hadnt even considered.

SMF spam blocked by CleanTalk