Backstabbing code!

tommerbob

Minecraft. :D
Reaction score
110
Hello helpers. :) Its been a while. I'm using a simple function to detect whether a unit is behind another unit:

JASS:

function Backstab takes unit attacker, unit target returns boolean
    local real casterfacing = GetUnitFacing(attacker)
    local real targetfacing = GetUnitFacing(target)
    if facecaster > (facetarget - 50.) and facecaster < (facetarget + 50.) then
        return true
    endif
    return false
endfunction


And it seems to work, but is there a better/more accurate way to do it?
 

tommerbob

Minecraft. :D
Reaction score
110

tommerbob

Minecraft. :D
Reaction score
110
Okay I got it working, but your code doesn't detect if a unit is behind another unit, it merely checks if the unit is inside a cone in front of another unit.

Despite that, this is actually really useful, this will help me with several multishot/aoe spells I'm trying to do. :)
 

Laiev

Hey Listen!!
Reaction score
188
sdlklk.png
 

luorax

Invasion in Duskwood
Reaction score
67
Yep, for facing of the unit use [ljass]360.-GetUnitFacing(target)[/ljass], and switch parameters in the [ljass]Atan[/ljass] call. I think that may solve the problem.
 

Dirac

22710180
Reaction score
147
Yep, for facing of the unit use [ljass]360.-GetUnitFacing(target)[/ljass], and switch parameters in the [ljass]Atan[/ljass] call. I think that may solve the problem.

????

To determine if an unit is behind another unit you must know which is the target's unit "field of view" which would be a cone with operture close to 45 degrees from the center (or 90 degrees total) and same facing as the unit's facing angle, then compare the facing of the unit with the angle between the target and the attacker and check if it's inside the given point

[ljass]Cone(GetUnitFacing(target)*bj_DEGTORAD,Atan2(GetUnitY(attacker)-GetUnitY(target),GetUnitY(attacker)-GetUnitY(target)),bj_PI/4)[/ljass]

That would be the best way to do it.
The best thing about using the "Cos" function is that it really doesn't matter if the angle is positive or negative, In any other case you would have to make the angle positive and then compare all 3 possibilities (over 360, between 360 and 0 and below 0)

TL;DR just use the Cone example I wrote above
 

luorax

Invasion in Duskwood
Reaction score
67
Well, I don't think I can reply to that message, I think I'm lost, my math is too sucky at the moment.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top