cecilofs' post below made a good point that the unit is deselected whenever you want to look with the camera. I've attached v2 of the solution below. Once "Lock Camera Mouse Relative Mode" is called, the unit is technically no longer highlighted because the cursor is automatically hidden.
The new solution makes use of the original, but now the unit is stored in another variable when the mouse is down. And when the mouse is released (Up), the "Highlight On" trigger will be called if a unit is highlighted. The new version checks that the mouse up highlighted unit is the same one as when the mouse was pressed down and highlights it if so!
Triggers
New Variable
Mouse Down
Setting new variable if highlighted unit exists
Highlight Off
Checks if highlighted unit is the same as the one when the mouse was pressed down
Original Post
Some of you may have played around with camera movement using the mouse. i.e. You click your mouse button and drag to move the camera around a point on the map. But there's one problem when using this technique: You can't click on anything to select it! This is a major problem for those wanting to be able to click as well as move the camera.
Following is a basic tutorial on my solution for this problem which works quite well. It also lets you de-select a unit by clicking on an empty space.
Here we go:
First we'll set up the camera. This will also allow you to see why the workaround is needed.
The Problem
Place your unit on the map. Here I chose an Archon since it's big and shiny.
Now make two triggers called "Mouse Down" and "Mouse Up". These will contain our events for when the mouse button is pressed down or up.
In your "Mouse Down" trigger, set it to look like the following:
"Mouse Up" should look like this, it's basically the opposite of the "Mouse Down" trigger since we just want to turn the camera rotation off.
Test the map! If you left click anywhere on the map and move your mouse you will see that the camera moves. But hang on, why don't you try and select your unit? You can't right? And there's the problem which we can fix with the following solution:
The Solution
The solution makes use of the in-built event that is triggered when you hover your mouse over a unit.
Add 2 new triggers called "Highlight On" and "Highlight Off" and 1 variable called "Highlighted Unit" and make its type a "Unit"
In "Highlight On" set it up to look like this:
"Highlight Off" is a little similar with a few tiny changes:
Head to your "Mouse Down" trigger and just before you turn on all the camera actions add the following: (Note that "deselect all units..." is called "Clear Unit Selection" in the action list.
That should be the last step right? Wrong. Last but not least we have to make the unit highlightable so that our highlight triggers actually work. To do this head into the Data Editor (Units), find your unit and uncheck Cannot Be Highlighted from Unit - Flags. I also unchecked Cannot Be Clicked purely for the sake of logic :P
Now test your map and you can see that you can not only move the camera with your mouse, but you may also click the unit and click off it to deselect! This should be very useful for those of you working on RPG type maps with a movable camera.
It works like you say it does. If not for wanting it to deselect the unit with a left click, you could have just added an into the left click trigger to select the unit at that point for the current player.
I found a few things frustrating with it - you can't click and drag and if you have your unit selected and then left click to rotate the camera, it deselects the unit. I guess its not an issue if you are using a different control system though.
Edit 2: New solution is prepended to the original post.
Edit: I just realised the solution below won't work since our original problem of the mouse cursor being hidden arises again and the Highlighted Unit variable will be emptied as when the camera is activated, the Highlight Off event is triggered.
Another work around can be added though to check if the same unit is still hovered when the mouse is released, and then select it. But make sure that if you click an empty area then release the mouse while hovering on a unit, that unit isn't selected.
Original Post
You bring up some good points. The reason the deselection action is in there is because without it, any units you click will be appended to the original selection instead of just one unit being selected.
As for the dragging issue, perhaps try utilising the Mouse Up trigger. For example:
Mouse Down
Set Variable - Mouse Down Unit <Unit> = Highlighted Unit.
Mouse Up
If Highlighted Unit = Mouse Down Unit
Then
Select Highlighted Unit
I haven't tested this yet, but it should select the unit when you release the mouse and complete a click action.
This could bring in some interesting twists to RTS games...
Maybe faster paced ones where players have resources and is able to call down "structures" that sets up and automates themselves to produce structures and basically have AI control the army...
Think nexus wars but more freeform and closer to melee... You're not forcing the AI to build and do certain things, you're guiding them.
Orbital Wars anyone? You drop base structures to be constructed by your team's scv bots, to produce units. You have to do it within a radius of influence, making it important to expand the "territory".
Hmm but i'm not a good map maker to bother with the triggers to make such a map, I attempted triggers once before and it killed my interests in mapping for SC2. D:
It's way harder and harsher than SC1 mapping... So technically you can say this is more programming and less scripting.
Contents
Edit
cecilofs' post below made a good point that the unit is deselected whenever you want to look with the camera. I've attached v2 of the solution below. Once "Lock Camera Mouse Relative Mode" is called, the unit is technically no longer highlighted because the cursor is automatically hidden.
The new solution makes use of the original, but now the unit is stored in another variable when the mouse is down. And when the mouse is released (Up), the "Highlight On" trigger will be called if a unit is highlighted. The new version checks that the mouse up highlighted unit is the same one as when the mouse was pressed down and highlights it if so!
Triggers
Mouse Down
Highlight Off
Original Post
Some of you may have played around with camera movement using the mouse. i.e. You click your mouse button and drag to move the camera around a point on the map. But there's one problem when using this technique: You can't click on anything to select it! This is a major problem for those wanting to be able to click as well as move the camera.
Following is a basic tutorial on my solution for this problem which works quite well. It also lets you de-select a unit by clicking on an empty space.
Here we go:
First we'll set up the camera. This will also allow you to see why the workaround is needed.
The Problem
The Solution
The solution makes use of the in-built event that is triggered when you hover your mouse over a unit.
Now test your map and you can see that you can not only move the camera with your mouse, but you may also click the unit and click off it to deselect! This should be very useful for those of you working on RPG type maps with a movable camera.
@Huesy: Go
It works like you say it does. If not for wanting it to deselect the unit with a left click, you could have just added an into the left click trigger to select the unit at that point for the current player.
I found a few things frustrating with it - you can't click and drag and if you have your unit selected and then left click to rotate the camera, it deselects the unit. I guess its not an issue if you are using a different control system though.
@cecilofs: Go
Edit 2: New solution is prepended to the original post.
Edit: I just realised the solution below won't work since our original problem of the mouse cursor being hidden arises again and the Highlighted Unit variable will be emptied as when the camera is activated, the Highlight Off event is triggered.
Another work around can be added though to check if the same unit is still hovered when the mouse is released, and then select it. But make sure that if you click an empty area then release the mouse while hovering on a unit, that unit isn't selected.
Original Post
You bring up some good points. The reason the deselection action is in there is because without it, any units you click will be appended to the original selection instead of just one unit being selected.
As for the dragging issue, perhaps try utilising the Mouse Up trigger. For example:
Mouse Down
Mouse Up
I haven't tested this yet, but it should select the unit when you release the mouse and complete a click action.
This could bring in some interesting twists to RTS games... Maybe faster paced ones where players have resources and is able to call down "structures" that sets up and automates themselves to produce structures and basically have AI control the army...
Think nexus wars but more freeform and closer to melee... You're not forcing the AI to build and do certain things, you're guiding them.
Orbital Wars anyone? You drop base structures to be constructed by your team's scv bots, to produce units. You have to do it within a radius of influence, making it important to expand the "territory".
Hmm but i'm not a good map maker to bother with the triggers to make such a map, I attempted triggers once before and it killed my interests in mapping for SC2. D:
It's way harder and harsher than SC1 mapping... So technically you can say this is more programming and less scripting.
Thanks Huesy.
dra6o0n - Cool idea. It sounds like Battlezone - First Person RTS.