WASD Movement: The 'S' Key and You
Author: deliverancelost (sc2mapster.com)Tags: beginner trigger interface  
Source: http://forums.sc2mapster.com/resour...Added 13 years ago 

This tutorial covers a couple different ways of implementing backwards movement in a third-person type map. There are already many tutorials on how to make a functioning WASD movement system and they are probably much better than I could do, so that will not be discussed here. I will give an overview of the trigger systems discussed, but I will be mostly covering the backwards movement part.

Example map: (link)


Part 1: How the !@#% do I turn this thing around?!
So there you are, fighting off the incoming Zerg swarm with your grenade launchers, and suddenly you see Dick Cheney running towards you carrying a rifle and wearing an orange vest. You check your pockets and realize you have left your crucifix at home. There's only one option: turning him your !@#hole and elbows and hightailing it out of there. Turning your camera all the way around before you can run would put you right on the first page of the New York Times in the worst way. Times like this you need your "S" key to do one thing: make your unit turn and run in one keystroke.

First, let's quickly go over my preferred trigger set for this type of movement. The images will speak for themselves. This is an 8 axis movement system that moves your unit in the direction pressed with respect to the camera facing.



This is the overview of the global variables and the number of triggers.



This is the trigger for moving forward. The key up triggers only set the variables as false. The A and D keys, if pressed with W, add 45 degrees to the direction of movement.

Ok, now for what I promised you:



As you can tell, this is very much like the "W down" trigger. The key difference is this line of code:
Variable - Set Angle = ((Camera Yaw of Player(1)) + 180.0)

This makes the local variable "Angle" point in the direction of the player camera. The rest of the trigger is the same as the forward movement one.

The A and D movement triggers are exactly the same, they do not deal with turning the camera, that is done with the mouse.



I know I said i wasn't going to spend so much time on the whole movement system, but there it is. If anyone wants me to upload a map with this movement system in it I will, just ask.


Part 2: Back that thang up?
Example map: (link)

Okay, my humor is getting worse and worse as it gets later, so I will spare you. Developing an S movement trigger where the unit did not turn around gave me fits, and looking back I am not sure why. I haven't seen much of this, but I think it is important. It's more like MMORPG movement systems where you don't want the unit to turn completely around especially if its abilities are only usable in front of it.

This is the type of system I am using in my Mechwarrior: Revival map. I don't want to post the whole triggers before I release a playable demo of it, but we can start from scratch.

I had to have the unit move backwards without turning around because slow turning and only being able to attack in front of the mech is a vital part of the mechanics. If pressing S instantly turned the unit around, then it wouldn't be anything like mechwarrior.

Let's start at the beginning, Create some boolean globals for W, A, S, and D. Set up your triggers for making the variables true when the key is pressed down, and false when it is pressed up. Something like this:

a down
Events:
    UI - Player Any Player presses A key Down with shift Allow, control Allow, alt Allow
Actions:
    Variable - Set a down = true


a up
Events:
    UI - Player Any Player presses A key Up with shift Allow, control Allow, alt Allow
Actions:
    Variable - Set a down = false


Ok, now that we have that, create a real global variable and name it "facing angle" Create another variable for the unit you want your player to control and declare it. I will just refer to it as "Unit" from this point on.
Next, create a trigger that looks like this:

move point
Events:
    Timer - Every 0.01 seconds of Game Time
Actions:
    Unit - Make Unit face facing angle over 0.0 seconds


Notice the rate at which the game corrects the facing angle of the unit. This is mandatory. The game engine makes the unit face the direction in which it is moving automatically. The trigger has to correct the angle as often as possible to keep the unit from turning around.

It is important for me to mention the triggers for turning, as this is not a common movement system.

turn right
Events:
    Timer - Every 0.01 seconds of Game Time
Conditions:
    d down == true
Actions:
    Variable - Set facing angle = (facing angle - 0.5)


Changing the "0.5" will change the rate at which the unit turns. A higher number will make the unit turn faster, and visa versa. The turn left trigger is the same, except the value is added to the facing angle, not subtracted. The periodic timing has to be very constant, as before, to make the movement look smooth.
Now for the good stuff, the backwards movement.

reverse
Events:
    Timer - Every 0.5 seconds of Game Time
Conditions:
    s down == true
Actions:
    Unit - Set Unit Movement Speed to 1.0
    Unit - Order Unit to ( Move targeting ((Position of Unit) offset by -1.0 towards (Facing of Unit) degrees)) (Replace Existing Orders)


The movement speed change is optional. If you don't want the unit to move backwards more slowly than it does forwards you can omit it. Remember if you use it to place a similar line of code in the W down trigger that resets the units movement speed to its original value every time you press W.

I think that should do it. Again, if anyone wants map files with these systems in them just ask and I will upload some.

Hope this helps everyone!






Star Depot
Contact      Login