Now make this script run on your Player Actor for a Key Down Event for any of the four keys pressed set to the following:
Key Down Event: a w s d. Execute when (At least one key is pressed.) Repeat: Disable.
Here is the Key Down script:
- Code: Select all
ThisKey = getLastKey();
switch (ThisKey)
{
case KEY_a: Btns+=1;
break;
case KEY_w: Btns+=2;
break;
case KEY_s: Btns+=4;
break;
case KEY_d: Btns+=8;
break;
}
And then do separate Key Up events for each button (w,a,s,d) for when it is released to deduct the value that was added when the button was pressed.
The script for button (a):
- Code: Select all
Btns-=1;
Each button has a number assigned to it and each number in this sequence is double the previous one so that any button combination produces a unique value, so if you press (w) and (a) together, the Btns variable becomes '3' (1+2=3), the values of (w) and (a) combined, then if you hold them down and also press (d), the value then adds up to '11'.
Using this system will allow for multiple keys to be pressed simultaneously without conflicts.
Now on Draw Actor Event for the Player Actor, put something like this script which will determine the current value of the Btns variable and respond by moving the player accordingly (Using compass directions of North, West, East, South in this case):
- Code: Select all
switch (Btns)
{
case 0: directional_velocity=0;//No keys pressed
break;
case 1: angle=180; directional_velocity=5;//Button (a) is being pressed so move player West.
break;
case 2: angle=90; directional_velocity=4;//N
break;
case 3: angle=153.43; directional_velocity=5;//NW
break;
case 4: angle=270; directional_velocity=4;//S
break;
case 5: angle=206.56; directional_velocity=5;//SW
break;
case 6: directional_velocity=0;
break;
case 7: angle=180; directional_velocity=5;//W
break;
case 8: angle=0; directional_velocity=5;//E
break;
case 9: directional_velocity=0;
break;
case 10: angle=26.56; directional_velocity=5;//NE
break;
case 11: angle=90; directional_velocity=4;//N
break;
case 12: angle=333.43; directional_velocity=5;//SE
break;
case 13: angle=270; directional_velocity=4;//S
break;
case 14: angle=0; directional_velocity=5;//E
break;
case 15: directional_velocity=0;
break;
}
This movement script was designed for an isometric game so change the list of responses to suit your needs. Here is an example .ged file to demonstrate how it works: