This is an advanced article on creating 3rd Person Control system. It assumes you know how to use the Trigger editor and some basics navigating the Galaxy Editor. You can download a working version of the 3rd person controls here: http://dl.dropbox.com/u/1940586/sc2-3psmovement-tut/ZerglingZapTut.SC2Map
Before We Trigger
We need a Unit to control, and for this tutorial, I will use an Archon. While much of the tutorial is unit independent, when we get to attacking, we will use the Archon attack for damage dealing, and other units don't have that.
So, Create an Archon for Player 1 in the center of the map. Also, create a circle region with the radius of 0.25 named CameraView
And then he said: Let there be Triggers
So, we got our Archon and our small area, Lets get crackin. Open up the Trigger editor and delete that pesky Melee Initialization trigger. Let's create a global variable that is of type Unit. I'm going to name it Player, and set it to our Archon. Also, I'm a fan of organization, so lets create a new folder in your Trigger Editor and name it Init. In this folder, we will put all of our initialization triggers.
Create a new Trigger named Init3ps. The Event will be (gasp) Map Initialization. For the actions, we have:
And run the map. You should now be looking at your Archon in 3rd Person mode! YAY!!!!! WOOP!!!
Tasty Trembling Triggers Rotating Round Rhombuses
Now we are going to have some fun with Movement. And by fun, I mean actually do it. Again, I like organization, so we are going to create TWO folders this time, One named 'Update' and the other named 'Movement'
Inside of Update, we will make a new Trigger named UpdateCamera. This trigger will keep the camera bounds correct while we move our unit, since the camera bounds will not follow a moving region for some reason. TBH, it feels like a bug, so I made this in a separate trigger from other update functions, so that if they fix the bug, we can quickly delete this part.
Create a Trigger in the Movement Folder named MoveForwardKeyDown. This is when you press the W key, you move forward. This is code roughly based on someone else's project, but I don't remember who. This is the most involved trigger here. The Move Order is fairly specific, and you need to make sure you use the function IssueOrderTargetingPoint
Triggering a move is great, now lets Trigger a WARRRRRR
Right, so we have movement and looking done, lets do some Awesome ATTACKING! RAAAAHHH ARCHON ZAP!!! Ahem.
Anyway, Head on back over to the terrain editor, and place some Zerglings for Player 2. We need something to Zap of course! We also need a Circle region that has a radius of 5 named 'ArchonAttackRange'.
Zerglings. Lol
After that, Take a quick hop skip and a jump over into the Trigger editor, and create a new folder named 'Attack'. If you can't tell, I REALLY like folders. Organization is great. Anyway, off that tangent. This process will be another few triggers, because we need to set up an attack radius, get every zergling in that radius, and then pick one to zap, preferably one that is close to us. WE CAN DO IT!
So, The first trigger we are going to make is the one that attaches the Attack Radius region to our Archon. In the Attack folder, create a new Trigger, 'AttachRadiusToPlayer'
Next, Create a new trigger named 'Attack'. This trigger is in quite a few parts, as it is pretty involved, and will use local variables (it makes things easier in the long run).
So, the first part is simple, make the event when player 1 presses left mouse.
Then, press Ctrl + B, or create a New Variable named 'TargetGroup'.
Now we have all of our units in that region we attached to our Archon. Lets pick one to destroy. Create another variable named 'Target'.
THIS IS IMPORTANT: Your target variable MUST MUST MUST come after your Target Group variable. TargetGroup needs to initialize first.
That's it for this tutorial. You may notice that the Archon will auto attack zerglings. Just go into the Data Editor and remove it's Attack ability, since we are making attacks ourselves. Make sure you don't remove it's Move ability though, cause we need that. Thanks for Reading.
Great, guide! However, you don't need to set the camera bounds. If you take out "set camera bounds" when you set the camera and in "update camera" "camera follow for player 1" will auto follow the player without the jumpy animation.
Great, guide! However, you don't need to set the camera bounds. If you take out "set camera bounds" when you set the camera and in "update camera" "camera follow for player 1" will auto follow the player without the jumpy animation.
So, after playing around with it, I can't get it working as you describe. The camera still pans with mouse relative mode on.
Great tutorial! I still got one question though. When you want to attack and you keep clicking the mouse button it just does the animation over before letting the previous one finish.
How to solve this?
Another thing, if I remove the Attack button it will run away when hit.
Ok i'm lost, how are you able to choose single objects for parameters with "group" requirements? i can't seem to be able to even set up the camera because i cannot seem to be able to set up (player group) and (unit group) values correctly.
But this doesn't work as there is no unit group created, I think. Therefore, following the Trigger editor this can't even be done.
Would love to see a working version.
The function you need is Player Group from Player(). The trigger text I used is not very clear on this, so I will go through today and fix the 3 instances I turn Players into PlayerGroups.
The map I made while building this tutorial is linked at the very top of the page, so you can use that to compare.
While there is no built in solution, I know you can get the pitch as a Real, and then clamp it to a certain value. I don't know if you can set the pitch exactly, but, poke around
Yeah, the camera will move around with the mouse as if it is a normal game until the unit you want it to follow is on screen. To fix this, set the starting camera to be on or near your unit so that it locks to that unit at the start of the game. After that, the camera should not pan away from that unit and will follow without the stuttering effect.
Great tutorial! I still got one question though. When you want to attack and you keep clicking the mouse button it just does the animation over before letting the previous one finish.
How to solve this?
Another thing, if I remove the Attack button it will run away when hit.
The running away is a default behavior of an idle unit. Fixing that was beyond the scope of the tutorial, but you have to go into the data editor and clear that behavior. As for waiting for the animation to finish, there is no way to get the time of the animation or whether or not the model is doing a certain animation, so no. You could, however, look at how long the animation plays, and limit executing that attack trigger until the animation time has passed since you last attacked.
Here it is. Currently it works very similar to yours except that your mouse shows, you can click to attack/move, and when you left click it will move the camera in the direction of the mouse (which can be used to turn, just like yours). However, I get an error when I left click saying the execution took too long, despite it working as intended. Take a look and tell me what you think.
You still have the issue where the camera pans when you rotate it, Which is what I limited with the restricting camera bounds. I guess it's just a bug that blizzard has to fix.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
This is an advanced article on creating 3rd Person Control system. It assumes you know how to use the Trigger editor and some basics navigating the Galaxy Editor. You can download a working version of the 3rd person controls here: http://dl.dropbox.com/u/1940586/sc2-3psmovement-tut/ZerglingZapTut.SC2Map
Before We Trigger
We need a Unit to control, and for this tutorial, I will use an Archon. While much of the tutorial is unit independent, when we get to attacking, we will use the Archon attack for damage dealing, and other units don't have that.
So, Create an Archon for Player 1 in the center of the map. Also, create a circle region with the radius of 0.25 named CameraView
And then he said: Let there be Triggers
So, we got our Archon and our small area, Lets get crackin. Open up the Trigger editor and delete that pesky Melee Initialization trigger. Let's create a global variable that is of type Unit. I'm going to name it Player, and set it to our Archon. Also, I'm a fan of organization, so lets create a new folder in your Trigger Editor and name it Init. In this folder, we will put all of our initialization triggers.
Create a new Trigger named Init3ps. The Event will be (gasp) Map Initialization. For the actions, we have:
And run the map. You should now be looking at your Archon in 3rd Person mode! YAY!!!!! WOOP!!!
Tasty Trembling Triggers Rotating Round Rhombuses
Now we are going to have some fun with Movement. And by fun, I mean actually do it. Again, I like organization, so we are going to create TWO folders this time, One named 'Update' and the other named 'Movement'
Inside of Update, we will make a new Trigger named UpdateCamera. This trigger will keep the camera bounds correct while we move our unit, since the camera bounds will not follow a moving region for some reason. TBH, it feels like a bug, so I made this in a separate trigger from other update functions, so that if they fix the bug, we can quickly delete this part.
Create a Trigger in the Movement Folder named MoveForwardKeyDown. This is when you press the W key, you move forward. This is code roughly based on someone else's project, but I don't remember who. This is the most involved trigger here. The Move Order is fairly specific, and you need to make sure you use the function IssueOrderTargetingPoint
Finally, we need to break this loop when we lift up the W key, so create a new Trigger named MoveForwardKeyUp. This one is pretty simple.
Triggering a move is great, now lets Trigger a WARRRRRR
Right, so we have movement and looking done, lets do some Awesome ATTACKING! RAAAAHHH ARCHON ZAP!!! Ahem.
Anyway, Head on back over to the terrain editor, and place some Zerglings for Player 2. We need something to Zap of course! We also need a Circle region that has a radius of 5 named 'ArchonAttackRange'. Zerglings. Lol
After that, Take a quick hop skip and a jump over into the Trigger editor, and create a new folder named 'Attack'. If you can't tell, I REALLY like folders. Organization is great. Anyway, off that tangent. This process will be another few triggers, because we need to set up an attack radius, get every zergling in that radius, and then pick one to zap, preferably one that is close to us. WE CAN DO IT!
So, The first trigger we are going to make is the one that attaches the Attack Radius region to our Archon. In the Attack folder, create a new Trigger, 'AttachRadiusToPlayer'
Next, Create a new trigger named 'Attack'. This trigger is in quite a few parts, as it is pretty involved, and will use local variables (it makes things easier in the long run).
So, the first part is simple, make the event when player 1 presses left mouse.
Then, press Ctrl + B, or create a New Variable named 'TargetGroup'.
Now we have all of our units in that region we attached to our Archon. Lets pick one to destroy. Create another variable named 'Target'. THIS IS IMPORTANT: Your target variable MUST MUST MUST come after your Target Group variable. TargetGroup needs to initialize first.
Now that we have our targets, Lets do something about it. Play the attack animation and if there is actually zerglings in our radius fire off a Zap!
Final Attack Trigger Code:
Run the map, it works now!
That's it for this tutorial. You may notice that the Archon will auto attack zerglings. Just go into the Data Editor and remove it's Attack ability, since we are making attacks ourselves. Make sure you don't remove it's Move ability though, cause we need that. Thanks for Reading.
Amazing tutorial, are you planning on writing how to rotate the camera/player with A and D
@Kylegar: Go
Sweet tutorial man; I can't wait to try out the 3rd person camera.
Kay, it's finished now.
Not in the scope of this tutorial, but it shouldn't be too hard to figure out.
@Kylegar: Go
ahh ok, do you use right click mouse to move from left to right?
No, the Archon will automatically move in the direction the camera is facing, and the camera moves naturally around the Archon.
Thanks for the guide! The third person movement is pretty awesome.
Is there an easy way to make the archon not run away when the zerglings attack?
Great, guide! However, you don't need to set the camera bounds. If you take out "set camera bounds" when you set the camera and in "update camera" "camera follow for player 1" will auto follow the player without the jumpy animation.
@SupDood: Go
Really? I will try this
So, after playing around with it, I can't get it working as you describe. The camera still pans with mouse relative mode on.
Great tutorial! I still got one question though. When you want to attack and you keep clicking the mouse button it just does the animation over before letting the previous one finish.
How to solve this?
Another thing, if I remove the Attack button it will run away when hit.
Ok i'm lost, how are you able to choose single objects for parameters with "group" requirements? i can't seem to be able to even set up the camera because i cannot seem to be able to set up (player group) and (unit group) values correctly.
It is possible that you need to aim at the unit you want to kill?
Yeah, like vrumpt said, this doesn't really work.
At least, the tutorial is inconclusive. I followed it directly and got a syntax error because of the following line:
But this doesn't work as there is no unit group created, I think. Therefore, following the Trigger editor this can't even be done.
Would love to see a working version.
I see your map has the same problem I posted about here: http://forums.sc2mapster.com/development/map-development/499-camera-pitch-restrictions/
Have you looked into any sort of solution?
This tutorial works, but some extra details would be neat. I had to find the correct buttons first too. But eventually got it all.
The function you need is Player Group from Player(). The trigger text I used is not very clear on this, so I will go through today and fix the 3 instances I turn Players into PlayerGroups.
The map I made while building this tutorial is linked at the very top of the page, so you can use that to compare.
While there is no built in solution, I know you can get the pitch as a Real, and then clamp it to a certain value. I don't know if you can set the pitch exactly, but, poke around
@Kylegar: Go
Yeah, the camera will move around with the mouse as if it is a normal game until the unit you want it to follow is on screen. To fix this, set the starting camera to be on or near your unit so that it locks to that unit at the start of the game. After that, the camera should not pan away from that unit and will follow without the stuttering effect.
@SupDood: Go
Do you have an example map of this? I'd like to see how you did it.
The running away is a default behavior of an idle unit. Fixing that was beyond the scope of the tutorial, but you have to go into the data editor and clear that behavior. As for waiting for the animation to finish, there is no way to get the time of the animation or whether or not the model is doing a certain animation, so no. You could, however, look at how long the animation plays, and limit executing that attack trigger until the animation time has passed since you last attacked.
Here it is. Currently it works very similar to yours except that your mouse shows, you can click to attack/move, and when you left click it will move the camera in the direction of the mouse (which can be used to turn, just like yours). However, I get an error when I left click saying the execution took too long, despite it working as intended. Take a look and tell me what you think.
@SupDood: Go
You still have the issue where the camera pans when you rotate it, Which is what I limited with the restricting camera bounds. I guess it's just a bug that blizzard has to fix.