Update: Both tutorial maps in place. Good luck with your projects! Hope this helps you out.
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.
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.
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
Local Variables
Conditions
Actions
Variable - Set a down = true
a up
Events
UI - Player Any Player presses A key Up with shift Allow, control Allow, alt Allow
Local Variables
Conditions
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
Local Variables
Conditions
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
Local Variables
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
Local Variables
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 everytime 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.
I'm just wondering what's wrong with move unit instantly? That seems much simpler to me and as far as I tested it seems to work well.
Edit: and you can cast on the move.
In many situations the move instantly seems to work well. The major issue I have with it is that after you pass a certain speed, the movement gets really choppy. Also in my experience if you have any sort of code that changes unit speed (moving more slowly backwards, etc) The animation speed is not effected and it looks like your unit is trying to moonwalk.
I can include a section on move instantly backwards movement if you like, honestly I didn't think about it when I wrote this tutorial.
I decided about an hour or 2 ago to make a demo for a DS game i thought of years ago and wanted a movement system before anything else. Came here, saw your map, copied the movement (didnt even use part 2 of the tutorial) and i LOVE it xD thanks
I took one look at ur movement triggers and loved em. Great stuff here.
I do have a question about the method used to turn your unit. Isn't there a function to turn a unit already built in? The turn speed is set in the data tables. Or so I thought?
And is the periodics .01 memory intensive?
I mean if there were like 8-12 players.
Sorry for being really bad at setting up triggers, but how would I go about setting up this kind of movement for multiple players?
Just making the assumption that this is for a single player.
Unit - Order Player Unit to ( Move targeting ((Position of Player Unit) offset by 2.0 towards ((Facing of Player Unit) - 17.0) degrees)) (Replace Existing Orders)
This is a good way to turn a unit while moving without having to use a local variable.
For the point the unit targets you use the arithmetic function then use the facing angle of unit function as one of the values.
Set the facing angle of unit function to the same unit your ordering to move.
For the second value in the arithmetic function you can adjust the - 17 to anything for example + 45 would move the unit in the other direct in a 45 degree angle.
I prefer to stick with low number though as it gives the turning a less choppy look. Of course the lower the turn amount the more actions it will require to make bigger turns.
I suppose the most obvious benefit to this is that it separates the camera and the units angle giving you more freedom with both.
EDIT: Something I wanted to add. If you do use the method where your triggers fire with timer events then I highly suggest that the trigger isn't Initially On and only turned on when the player presses w, a, s, or d down. In the "key up" triggers you could add "if, then, else" actions with a condition to check if all the "key up" variables are false then disable the trigger again.
This could prevent a lot of lag from the trigger running every .01 or whatever its set to. Honest if your not using the variable method to turn then you probably wont need to use such a small amount of time so .1 or even slightly more is enough.
I have this on my map and also have right-click turn Camera Mouse Relative Mode and Camera Mouse Rotation on, but that means when I move the camera, "angle" changes, dependent on the camera. How do you set it to turn the camera WITHOUT affecting "angle"? (like left-click in WoW)
Update: Both tutorial maps in place. Good luck with your projects! Hope this helps you out.
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.
Part 1: How the !@#% do I turn this thing around?!
Tutorial map: Link Removed: http://www.mediafire.com/?qmnjjjymm2k
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?
Tutorial map: Link Removed: http://www.mediafire.com/?gwkoiqzwvn4
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
Local Variables
Conditions
Actions
Variable - Set a down = true
a up
Events
UI - Player Any Player presses A key Up with shift Allow, control Allow, alt Allow
Local Variables
Conditions
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
Local Variables
Conditions
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
Local Variables
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
Local Variables
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 everytime 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!
If u have time i would appreciate the maps :D sebbN
haha awesome section names and great tut =P
There you go, hope that helps!
I'm just wondering what's wrong with move unit instantly? That seems much simpler to me and as far as I tested it seems to work well.
Edit: and you can cast on the move.
In many situations the move instantly seems to work well. The major issue I have with it is that after you pass a certain speed, the movement gets really choppy. Also in my experience if you have any sort of code that changes unit speed (moving more slowly backwards, etc) The animation speed is not effected and it looks like your unit is trying to moonwalk.
I can include a section on move instantly backwards movement if you like, honestly I didn't think about it when I wrote this tutorial.
Can I copy from this, and if so, do you want recognition?
I decided about an hour or 2 ago to make a demo for a DS game i thought of years ago and wanted a movement system before anything else. Came here, saw your map, copied the movement (didnt even use part 2 of the tutorial) and i LOVE it xD thanks
I took one look at ur movement triggers and loved em. Great stuff here.
I do have a question about the method used to turn your unit. Isn't there a function to turn a unit already built in? The turn speed is set in the data tables. Or so I thought?
And is the periodics .01 memory intensive? I mean if there were like 8-12 players.
Wow, I feel stupid. I hadn't even thought of using variables to determine if a key is pressed or not.
Sorry for being really bad at setting up triggers, but how would I go about setting up this kind of movement for multiple players? Just making the assumption that this is for a single player.
Unit - Order Player Unit to ( Move targeting ((Position of Player Unit) offset by 2.0 towards ((Facing of Player Unit) - 17.0) degrees)) (Replace Existing Orders)
This is a good way to turn a unit while moving without having to use a local variable.
For the point the unit targets you use the arithmetic function then use the facing angle of unit function as one of the values.
Set the facing angle of unit function to the same unit your ordering to move.
For the second value in the arithmetic function you can adjust the - 17 to anything for example + 45 would move the unit in the other direct in a 45 degree angle.
I prefer to stick with low number though as it gives the turning a less choppy look. Of course the lower the turn amount the more actions it will require to make bigger turns.
I suppose the most obvious benefit to this is that it separates the camera and the units angle giving you more freedom with both.
EDIT: Something I wanted to add. If you do use the method where your triggers fire with timer events then I highly suggest that the trigger isn't Initially On and only turned on when the player presses w, a, s, or d down. In the "key up" triggers you could add "if, then, else" actions with a condition to check if all the "key up" variables are false then disable the trigger again.
This could prevent a lot of lag from the trigger running every .01 or whatever its set to. Honest if your not using the variable method to turn then you probably wont need to use such a small amount of time so .1 or even slightly more is enough.
I have this on my map and also have right-click turn Camera Mouse Relative Mode and Camera Mouse Rotation on, but that means when I move the camera, "angle" changes, dependent on the camera. How do you set it to turn the camera WITHOUT affecting "angle"? (like left-click in WoW)
just curious, does this system work for 8-12 players?
would the input delay, and any trigger lag make the map unplayable for 8-12 players?
or is the input delay and/or trigger lag be stable and manageable?