Running with the keyboard...

Started by JimmyD, Wed 03/09/2008 20:26:04

Previous topic - Next topic

JimmyD

I'm making a situation in which the character is moved using the keyboard (press, rather than tap), and am trying to implement a system of running when a different key is held along with the direction arrow. From what I've read of a several year old thread, the animation needs to pause briefly before character speed can be changed.

Couple of things - the previous thread came from the days before the KeyboardMovement module came with AGS. Should I be making the additional script within the KeyboardMovement module, or in repeadtedly_execute?

I'm sure I'll get this scripting lark figured out eventually!

JimmyD

Well, I've found a semi-solution to my problem. I've opted to have run and walk as two discrete modes - when you press tab, it shifts between the two, depending on whether the int "running" is 1 or 0. In on_key_press I've put the following in:


  if (keycode == 9 && running == 0) {
    running = 1;
    player.LockView(2);
    player.SetWalkSpeed(8, 8 );
    return;
  }
 
   if (keycode == 9 && running == 1) {
    running = 0;
    player.LockView(1);
    player.SetWalkSpeed(4, 4);
    return;
  }


Basically, this succeeds in changing the view to a running view, and altering the player's speed when tab is pressed.

Is there any way to get around the player standing still when the speed changes, or is that something I'm going to have to work around, like having some kind of slow-to-fast change animation to mask it? Is there a way to set it to work when tab is held, rather than a press?

TwinMoon

#2
I can help you a little:

Code: ags

if (IsKeyPressed(9) == 1) {
  running = 1;
else {
  running = 0;
}


If you put this code in the repeatedly_execute the variable running will be set to 1 whenever tab is held, and set to 0 when it's not.


And if you want to change his walking speed, you'll have to stop him from moving first. There's no way around it.
However, what you could do is store the co-ordinates the player is walking to. Then you could do something like:

Code: ags
running = 1;
player.StopMoving();
player.SetWalkSpeed(8,8);
player.ChangeView(playerRunning);
player.Walk(movetox, movetoy);


(in which movetox and movetoy are the co-ordinates stored)

SMF spam blocked by CleanTalk