Quick Question - Detecting units in front

Trithilon-V2

New Member
Reaction score
20
OK guyz...i am making custom made cleaving attack (i used orb effect buff system to detect physical or magical attack)
Now all i need to know is how do i detect units in front of my unit in a semi circular fashion?
 
Reaction score
86
Doesn't work 100%
The only difference is, change the actions to whatever you want. In this example he only faces the unit.
 

Trithilon-V2

New Member
Reaction score
20
Thx..lemme chec....if this works..

EDIT:- I had to Modify your trigger to make it fully functionable ,although its now perfect....Thanks a Million..i was looking for such a flexible system since a long time....
I modded it to detect if the unit is in front, besides or behind...
You should make it into a system and post it dude or if you are not feeling like it them allow me to add a few more functions and post it (Credits to you)....
 

Attachments

  • Unit Facing Side.w3x
    17.7 KB · Views: 58
Reaction score
86
Go for it ^^ I don't mind. I made it for someone else though... Much appreciated if you did. I'll help you if you want ^^

+ Doesn't work perfectly. In my earlier example, the angle of the unit that was suppose to face the other unit(if such unit was in front), didn't work because when the unit that is suppose to turn was facing the 4th quadrant, and the other unit was in the 1st quadrant it would not turn because an angle such as 340 + 45 would be 385. While the angle from the unit would be something like 10. Technically the unit is in front, but it doesn't recognize it as so. Same with the example you posted. I will try and fix it now.
20gxxki.jpg

As shown above...
o_O Double post.... Can someone delete earlier one o_O
 
Reaction score
86
Got it, thanks anyway though ^^

Here should work perfectly. Tested most of it (not rigorously but tested enough.)
 

Trithilon-V2

New Member
Reaction score
20
Checking...i am on it...

EDIT :- Looks like its not working for units which stand besides the right hand side of the foot man...i have implemented a radar system to visibly show the boundaries....



However that system fails to detect a unit beside it.....I have uploaded the new version including the radar for ease of testing....
Waiting for your response...dude plz fix this...

PS. Forgive the leaks
 

Attachments

  • Unit Facing Side V2.w3x
    20.8 KB · Views: 69

Trithilon-V2

New Member
Reaction score
20
Thx Dude....It works like a charm.....
+ Repped ya.....
Although i removed a unitgroup and a playergroup leak but it still laggs..........
However it serves the purpose....
 
Reaction score
86
Know Jass? Maybe streamlining it into Jass will increase speed? (Local Variables so we don't have to keep calling these functions.)
 

Trithilon-V2

New Member
Reaction score
20
Unfortunetely i dont know Jass....
I however was gonna ask you to convert this stuff into a neat function....
I'll ask my friend to Jassify this one...
 

Trithilon-V2

New Member
Reaction score
20
Sure....will let u know when done...all i know is how to call functions and get return values....
Btw i'll be enjoying my upgraded Attack Detection system giving me total ctrl over each n every bit of damage....
 

martix

There is no spoon
Reaction score
49
Code:
Facing Detect
    Events
    Conditions
    Actions
        Set SourceUnit = YourUnit
        Set TargetUnit = YourUnit
        Set DetectionAngle = 20.00
        Custom script:   set udg_UnitX = GetUnitX(udg_TargetUnit)
        Custom script:   set udg_UnitY = GetUnitY(udg_TargetUnit)
        Set FaceAngle = (Facing of SourceUnit)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                Or - Any (Conditions) are true
                    Conditions
                        (Atan2(UnitY, UnitX)) Less than or equal to (FaceAngle + (DetectionAngle / 2.00))
                        (Atan2(UnitY, UnitX)) Greater than or equal to (FaceAngle - (DetectionAngle / 2.00))
            Then - Actions
                Set IsInFront = True
            Else - Actions
This is what I have come up with, it does not require jass, just 2 lines of custom script.
I haven't tested it, but I think it should work...
Atan2 being the "Arctangent from deltas" math function.
DetectionAngle is how the much the angle of detection is.
Right now it detects units that are in a 20 degree cone in front of your source unit.
 

Azylaminaz

Vox Populi
Reaction score
91
Custom scripts aren't even required, you can get the point position of unit and get X/Y from that.

Of course you will want to clear up memory leaks in custom scripts. ;P
 

martix

There is no spoon
Reaction score
49
Er, I am not seing any leaks. I am using coordinates, not locations, so... Its either that or a custom script to remove the leaks from the locations that will be used the other way.
 

Trithilon-V2

New Member
Reaction score
20
Would be awesome if this works...although i dont know what arctangent is.
I am in college right now...I'll test it and let u know as i reach home...
 
General chit-chat
Help Users

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top