• 🏆 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!

Angles and "backstabs"

Status
Not open for further replies.
Hi.
I am using a system in my map to detect which direction an attack is coming from to decide how front, side, and rear armor affects the damage.

This is how my code looks for the angle detection itself:

JASS:
function Front takes unit u, unit t returns boolean
    return RAbsBJ(GetUnitFacing(t)-GetUnitFacing(u)) >= 35.
endfunction
function Back takes unit u, unit t returns boolean
    return not (RAbsBJ(GetUnitFacing(t)-GetUnitFacing(u)) >= 145.)
endfunction

Then i have this script for puting it to practice:
JASS:
if Back(u1, u2) then
call BJDebugMsg("Back")
else 
if Front(u1, u2) then
call BJDebugMsg("Front")
else 
call BJDebugMsg("Side")
endif
endif

As you see, i'm assuming that if the direction is neither from the back nor front, it has to be from the side.
There are two problems with this though; firstly, it appears that the system will jude something as EITHER back or front, sides are simply never registered. I think this have to do with the Back function, but i just can't visualize how the angles look by just seing theese numbers.

The other problem is that it is exploitable. I know that this is the most commonly used method, but i would like it to use the units location rather than facing angle.

Can someone show me how it should be?
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
This tutorial may help you detect an attack from the back. (Specifically, look at the function, Backstab_GetAngleDifference)
For angles, I use the angle between the target and caster and the facing angle of the target. I don't think it will be that much of a problem if you just use facing angle for both though.
Note: The function takes the angles in degress, though it shouldn't be too hard if you wanted the function to take radians. (Just replace 360 with an approximation of Pi times 2.)

I don't know how you would detect side with it though it shouldn't be too hard.
 
Status
Not open for further replies.
Top