HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Angle Between Points

01-23-2006, 06:25 AM#1
Beeva186
Hello again. This time I'm trying to make an ability that, when cast, sends out a flash of light and heat
that damages nearby units, but, if they are facing in the direction of the casting unit (or almost facing)
then it does lots more damage and blinds them (just a modified curse). I know how to do everything
except the extra damage for units facing the caster. I tried to do something like this-
Code:
Sear
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Sear 
    Actions
        Set UNITCASTER = (Triggering unit)
        Set POINTCASTPOINT = (Position of (Triggering unit))
        Unit Group - Add all units of (Units within 550.00 of POINTCASTPOINT) to GROUPAFFECTED
        Unit Group - Pick every unit in GROUPAFFECTED and do (Actions)
            Loop - Actions
                Set POINTANGLE = (Position of (Picked unit))
                Unit - Cause UNITCASTER to damage (Picked unit), dealing (1000.00 / ((Distance between POINTANGLE and POINTCASTPOINT) x ((Angle from POINTANGLE to POINTCASTPOINT) - (Facing of (Picked unit))))) damage of attack type Spells and damage type Magic

Rough, (i know there's memory leaks but i'll fix them later), but my problem is that if the unit is facing
a tiny bit off the caster, it deals strange amounts of damage (because it goes directly from zero degrees
to 360 degrees). Does anyone know how to do this properly or a different way to do it?
01-23-2006, 08:20 AM#2
Azazel_
Code:
function SearDamage takes nothing returns nothing
    local unit u = GetEnumUnit()
    local location l = GetUnitLoc(u)
    local real r = bj_RADTODEG * Atan2(GetLocationY(udg_SearLoc) - GetLocationY(l), GetLocationX(udg_SearLoc) - GetLocationX(l))
    local real unitface = GetUnitFacing(u)
    call UnitDamageTarget( udg_SearCaster, RMaxBJ( 0, u, 200 - ( SQR((r - unitfacing)^2) * 2 ) ), true, true, ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DEMOLITION ,WEAPON_TYPE_MAGIC) )
    call RemoveLocation(l)
    set l = null
    set u = null
endfunction

function Sear takes nothing returns nothing
    if (GetSpellAbilityId() != SearSpellId ) then
         return
    endif
    set udg_SearCaster = GetTriggerUnit()
    set udg_SearLoc = GetSpellTargetLoc()
    set udg_SearGroup = GroupEnumUnitsInRangeOfLoc( udg_SearGroup, udg_searloc, 550.0, null )
    ForGroup( udg_SearGroup, function SearDamage )
    call DestroyGroup(udg_SearGroup)
    call RemoveLocation(udg_SearLoc)
endfunction
Collapse JASS:
function SearInit takes unit u returns nothing //u is the specific hero that is going to use this spell
    local trigger t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_SPELL_CAST )
    call TriggerAddAction( t, function Sear )
    call UnitAddAbility(u, SearSpellId) //Preload Spell
    call UnitRemoveAbility(u, SearSpellId)
    set t = null
endfunction

This is the gist of it. Damage done by a direct face is 200 damage, and each degree away from the direct sear deals 2 less damage. If you are facing 40 degrees away from the direct sear degree, you get hit with 120 damage. The further you turn, the less damage there is. A 90 degree difference means 20 damage. This should be about right, as beyond that, you should not be able to 'see' the sear.

- Remove the need for condtions.
- 200 and 5 values are adjusted to your preference.
- Leaks solved, but that's just a side issue.

The main point here is just the generation of idea. Go to www.wc3jass.com to complete the details. I am posting in JASS not because of intellectual arrogance, but because I do not know how to write the GUI on these forums, and the Jass method is optimal and the best long run solution, I believe. It also involves greater learning and enrichment.
01-23-2006, 08:31 AM#3
SortOf
Real Casting Unit Faceing Equal to Targeted unit Faceing -180 Or do it twice with atlest 160 , at most 190 seems like it would work i may of tryed this before and it failed
01-24-2006, 12:53 AM#4
Beeva186
Hmm thanks guys, I think I understand the maths in that JASS... I'll work on it some more. Ta muchly.