Ever notice that when your mouse hovers over a unit, it changes from a pointer to a box. This is event is known as "Unit is Highlighted."
So, besides for a few special cases, we can make a traceline that detects collision with units, collision with doodads and collision with terrain, all in one, very simple function.
Ready?
Event - Unit is Highlighted
Set TraceTarget[unit variable] = Triggering unit
-----------------
Event 2 - Unit is Unhilighted
Set Trace Target = No unit
-----------------
When shooting your weapon:
Event 3 - [Player shoots their weapon]
If/Then/Else-
If: Tracetarget is NOT equal to No Unit
Then: Order[weapon unit] to attack Trace Target
Else: Create a Dummy Unit at (Point - Position of Camera) offset by Distance(Cosine(Pitch of Camera) towards (Yaw of Camera degrees)
Set Last created unit Height to { Distance(Sine(Pitch of Camera)) - [Ground Height at Position of Dummy Unit - Ground Height at Position of Player Camera] + Height Offset of Player Cam }
Else (same else): Set TraceTarget = Last Created Unit
Else(same else): Order[weapon unit] to attack Trace Target
--------------------
Congratuations, You Won!
(don't forget to have a system that deletes the dummy units after a particular time expiration)
Each unit in the data editor has the flag "Cannot be Highlighted" be default. So every unit you intend to use (that can be shot at) needs to have this unchecked in Unit Flags.
One obstacle remains: If they player holds their left click down, in an attempt to select something, the highlight function becomes disabled until they release their left click, hmm how to fix?
Solution 1:
Do not use mouse event Left Click for shooting. Use Right click
Make your Left Click the special fire ability, perhps some sort of projectile with slow a slow rate of fire, this way your player won't hold the Left Mouse down for more than a split second.
BTW - for highlight state i use trigger, that turn on highlight state on all units every 2 seconds :D
PS: One request, please! Could someone create a blank map with a trigger for these lines? :
--
Else: Create a Dummy Unit at (Point - Position of Camera) offset by Distance(Cosine(Pitch of Camera) towards (Yaw of Camera degrees)
Set Last created unit Height to { Distance(Sine(Pitch of Camera)) - [Ground Height at Position of Dummy Unit - Ground Height at Position of Player Camera] + Height Offset of Player Cam }
Ever notice that when your mouse hovers over a unit, it changes from a pointer to a box. This is event is known as "Unit is Highlighted."
So, besides for a few special cases, we can make a traceline that detects collision with units, collision with doodads and collision with terrain, all in one, very simple function.
Ready?
Event - Unit is Highlighted
Set TraceTarget[unit variable] = Triggering unit
-----------------Event 2 - Unit is Unhilighted
Set Trace Target = No unit
-----------------When shooting your weapon:
Event 3 - [Player shoots their weapon]
If/Then/Else- If: Tracetarget is NOT equal to No Unit
Then: Order[weapon unit] to attack Trace Target
Else: Create a Dummy Unit at (Point - Position of Camera) offset by Distance(Cosine(Pitch of Camera) towards (Yaw of Camera degrees)
Set Last created unit Height to { Distance(Sine(Pitch of Camera)) - [Ground Height at Position of Dummy Unit - Ground Height at Position of Player Camera] + Height Offset of Player Cam }
Else (same else): Set TraceTarget = Last Created Unit
Else(same else): Order[weapon unit] to attack Trace Target
--------------------Congratuations, You Won!
(don't forget to have a system that deletes the dummy units after a particular time expiration)
Each unit in the data editor has the flag "Cannot be Highlighted" be default. So every unit you intend to use (that can be shot at) needs to have this unchecked in Unit Flags.
@EdwardSolomon: Go
One obstacle remains: If they player holds their left click down, in an attempt to select something, the highlight function becomes disabled until they release their left click, hmm how to fix?
Solution 1:
Do not use mouse event Left Click for shooting. Use Right click
Make your Left Click the special fire ability, perhps some sort of projectile with slow a slow rate of fire, this way your player won't hold the Left Mouse down for more than a split second.
genius...
So close to my system) Thanks for this tutorial!
BTW - for highlight state i use trigger, that turn on highlight state on all units every 2 seconds :D
PS: One request, please! Could someone create a blank map with a trigger for these lines? :
--Else: Create a Dummy Unit at (Point - Position of Camera) offset by Distance(Cosine(Pitch of Camera) towards (Yaw of Camera degrees)
Set Last created unit Height to { Distance(Sine(Pitch of Camera)) - [Ground Height at Position of Dummy Unit - Ground Height at Position of Player Camera] + Height Offset of Player Cam }
---No one can help? Ehh... :(
I was on Starcraft 2 vacation, now I'm back, what's up?