• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Picking closest target in front of a unit

Status
Not open for further replies.
Level 7
Joined
May 11, 2010
Messages
278
Hey everyone! Long time no see. I'm back to making maps and I've already run into a problem. That's what I get for taking an 8 month break I guess :p

I want to make an ability that targets the unit that is closest to the caster, but it should only target units that the caster is facing. So if the caster has one unit 50 distance behind him and another unit 200 distance in front of him, it should target the one in front of him.

Now, I know how to pick the closest unit, but how do i check if the caster is facing that unit? I'm kind of at a loss here. Also, it should be limited to something along the lines of sight range, but that shouldn't be too hard.
I'd prefer a GUI solution.
 
Level 14
Joined
Nov 17, 2010
Messages
1,265
I think your best bet would be to select units in an area with an offset. You would have to set a point that is x distance away from your unit towards facing angle of your unit. Then you would want to pick all units near that point. Then calculate the distance between the picked units and your unit and choose the one with the smallest distance.

That is basic idea, but someone else would probably be able to give you a trigger that is fast and efficient. Although your best bet would be to see if you can do it yourself then if it doesn't work or doesn't work right someone would be able to help you adjust it.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Level 10
Joined
May 21, 2006
Messages
323
  • Unbezeichneter Auslöser 005
    • Events
      • Conditions
      • Actions
        • Set TempReal = 0.00
        • Set Point[0] = (Position of (Triggering unit))
        • Unitgroup - Pick every unit in TempGroup and do (Actions)
          • Loop - Actions
            • Set TempUnit2 = (Picked unit)
            • Set Point[1] = (Position of TempUnit2)
            • Set TempReal2 = (Distance between Point[0] and Point[1])
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • 'IF'-Bedingungen
                  • TempReal Kleiner als (<) TempReal2
                • 'THEN'-Aktionen
                  • -------- XXXXXXXXXXXXXXXXXXXXXXXXXx --------
                  • Set SpellChannel_Target[0] = TempUnit2
                  • -------- XXXXXXXXXXXXXXXXXXXXXXXXXx --------
                  • Set TempReal = TempReal2
                • 'ELSE'-Aktionen
            • Point - Remove Point[1]
        • Point - Remove Point[0]
This will give you the closest unit. Which UnitGroup you take is up to you, remember to only put all enemy units into this group.
 
Level 7
Joined
May 11, 2010
Messages
278
@Veritas: I was thinking something like that, but it feels like that would be a really inefficient way to solve it. Thanks for the suggestion though.
@Chaosy: I know no JASS :p Sometimes I use JASS scripts other people have written to make triggers more efficient, but I prefer to avoid it as I want to understand what my code does.
@IcemanBo: The stars align. That seems too efficient to not use. Thank you!
@Zunariel: That doesn't check the facing of the unit though.


EDIT: I took a look at the Jass script. I have no clue of how to use it in my map. Now I either need someone to explain how to use it, or another solution :p
I'm gonna try to make a GUI solution along the lines of what Veritas suggested. Posting later.
Oh, and thanks to @Chasin for the link to Makers post, that was certainly helpful
 
Level 7
Joined
May 11, 2010
Messages
278
Okay, so I just played about with Makers solution, the one @chasin linked, and it turns out it's pretty great. If I just add a conditional that checks distance to it it's perfect. Thanks for the help!
 
Status
Not open for further replies.
Top