Difference between revisions of "WASD"

From HIVE
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 70: Line 70:
 
===Video Tutorial===
 
===Video Tutorial===
 
All credits of this video goes to JB4Times4, member of StarEdit Network's community.
 
All credits of this video goes to JB4Times4, member of StarEdit Network's community.
<youtube>http://www.youtube.com/watch?v=Ak0Ew1ts0MM</youtube>
+
<youtube>Ak0Ew1ts0MM</youtube>
  
[[Category:StarCraft II]][[Category:Tutorials]][[Category:Reference]][[Category:Triggers]]
+
[[Category:StarCraft II]][[Category:Tutorials]][[Category:Reference]][[Category:Triggers]][[Category:Video Tutorials]]

Latest revision as of 23:38, 13 December 2010

Trigger Method

WASD movement is a very simple thing to implement through either triggers or the data editor.

Global Variables

A Global Variable is a variable that stores information which can be accessed by any trigger or function. This is opposed to a local variable which can only be accessed within the trigger it is created. Parameters are another thing, but in simple terms, a parameter is a local variable being passed between triggers or shared.

So, to start off with our WASD movement system do this: in the trigger editor, press Ctrl+B to create a new global variable.

Create the following variables:

  • W_Down = (Type Boolean, default: False)
  • A_Down = (Type Boolean, default: False)
  • S_Down = (Type Boolean, default: False)
  • D_Down = (Type Boolean, default: False)

What these variables will hold, is whether or not our player is holding a key down.

Periodically Check the state of our Variables

Next up, we want to periodically check which state each of our variables is in. Then, according to their states, we will order our unit to move accordingly.

Create a trigger along these lines:

  • Event: Every 0.0 seconds of Game Time
  • Conditions: Empty.
  • Actions:
    • If - W_Down = True AND A_Down = False AND D_Down = False
    • Then - order our unit to move north by 0.5 units.
    • Else - new if, else, then statement
      • If W_Down = True AND A_Down = False AND D_Down = True
      • Then - order our unit to move north-east by 0.5 units.
      • Else - new if, else, then statement
        • If W_Down = True AND A_Down = True AND D_Down = False
        • Then - order our unit to move north-west by 0.5 units.

Repeat the above trigger-layout for each of our 8 directions. North, North-East, North-West, South, South-East, South-West, West and East.

Changing the state of our Variables

We will now make 8 triggers. Two for each of our keys, and whether they are being pressed_down or released_up.

For example, two triggers will look like this:

  • Event: Any Player presses W_Key Down (with shift, alt, control allow)
  • Conditions: Empty.
  • Actions: Set Variable - Set W_Down = True

The second trigger will do the exact same, except in reverse.

  • Event: Any Player presses W_Key UP (with shift, alt, control allow)
  • Conditions: Empty.
  • Actions: Set Variable - Set W_Down = False

Repeat this set up for the remaining A, S and D keys.

Note for fellow Wiki-Writers and Map-Makers

I believe this system is relatively lagless. The reason I believe this is due to the fact that the Key-Press event is kept to a minimum. The key-press event will modify the local variable which will determine the players movement over an indefinite period of time. Of course, a player could spam WA, WD and W key-press combinations by releasing and pressing repeatedly. But for the most part, I believe this system to work pretty well.

Further Note

I created this from scratch - without reference to my Galaxy Editor nearby. I will modify and update this with more clarity in the near future.

ESDF Alternative

ESDF (where E is forward, D is backward, S and left and F is right) is shorthand for an alternative to the more commonly used WASD control scheme (in which W is forward, S is backward, A and left and D is right). They are both used in many different games to control movement of a single unit or soldier, often in conjunction with the mouse. The differences between them are minor, but the main advantage of ESDF is that it allows the player to use nearby keys as hotkeys for abilities or something else as well.

Standard WASD allows the player to easily reach Q, E, Z, and X and with more strain 1, 2, 3 and C. ESDF, however, allows easy access to W, A, Z, X, C, V, R and G, and with more strain Q, 1, 2, 3, 4. Therefore, using ESDF may be preferable if you intend to give the player many options for what to do and you want them to be accessed via hotkeys rather than mouse-clicks.

One disadvantage of ESDF is that, being less popular, it's subject to key jamming. Key jamming occurs when keyboards aren't able to send certain combinations of letters due to hardware limitations. When certain keys are pressed very quickly or at the same time, jamming may occur, causing one of the keypresses to be "lost". WASD, being so popular, suffers from no key jamming; for ESDF, jamming is rare but not unheard of.

See Also

Video Tutorial

All credits of this video goes to JB4Times4, member of StarEdit Network's community. <youtube>Ak0Ew1ts0MM</youtube>