04292009, 09:15 AM  #1  
Overdoses result in death
Join Date: Jan 2007
Posts: 2,365

[Help] Keeping a lightning in a damn box
JASS: function Trig_Attacks_Actions takes nothing returns nothing local integer ATTACK_TYPE = GetSpellAbilityId() local unit attacker = GetTriggerUnit() local unit attacked = GetSpellTargetUnit() local real x1 = GetUnitX(attacker) local real y1 = GetUnitY(attacker) local real x2 = GetUnitX(attacked) local real y2 = GetUnitY(attacked) local real x3 = 0 local real y3 = 0 local real grad = 0 local real r = 0 local integer i = 0 if ATTACK_TYPE == 'A000' then // Laser attack loop set i = i + 1 exitwhen i == udg_LASER_Max or udg_LASER_InUse[i] == false endloop set udg_LocSPFX = Location(0,0) set udg_LASER_Bolt[i] = AddLightningLoc( udg_LASER_Type[GetUnitAbilityLevel(attacker,ATTACK_TYPE)], udg_LocSPFX, udg_LocSPFX ) set udg_LASER_Fade1[i] = 1.5 set udg_LASER_Fade2[i] = 0.02 set udg_LASER_FadeHold[i] = 0 set udg_LASER_Full[i] = 1.0 set udg_LASER_InUse[i] = true set udg_LASER_R[i] = 1.0 set udg_LASER_G[i] = 1.0 set udg_LASER_B[i] = 1.0 set grad = (y2  y1) / (x2  x1) set r = y1  grad * x1 if x2 < x1 then set x3 = GetRectMinX(udg_PlayerRegion[GetPlayerId(GetOwningPlayer(attacker))]) set y3 = (grad * x3) + r else set x3 = GetRectMaxX(udg_PlayerRegion[GetPlayerId(GetOwningPlayer(attacker))]) set y3 = (grad * x3) + r endif call SetLightningColorBJ( udg_LASER_Bolt[i], 0.25, 1., 1., 1 ) call MoveLightningEx( udg_LASER_Bolt[i], true, x1, y1, 50, x3, y3, 50 ) endif endfunction //=========================================================================== function InitTrig_Attacks takes nothing returns nothing set gg_trg_Attacks = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Attacks, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddAction( gg_trg_Attacks, function Trig_Attacks_Actions ) endfunction The issue with the highlighted section is that it confines stuff into an infinite rectangle involving the maximum and minimum Y, but not into a finite square involving the maximum and minimum X. What the problem is: I have a square and I have several lasershooting units inside it. The laser is confined with a maximum distance to the left and right, but there are no constrictions for the top and bottom. What I need to fix it is: Solved  An accurate formula that gets a line going through 2 points, starting from the "first one" of them, but still staying inside the square  A way of "closing" the laser from going through the top and bottom boundaries of the square
Last edited by TideArc Ephemera : 04292009 at 01:00 PM. 

Sponsored Links  Login to hide this ad! 

04292009, 12:11 PM  #2 
oO
Join Date: Jul 2008
Posts: 580

[jass]
known:x1,x2,y1,y2 local real m = (y2y1)/(x2x1) local real b = y1  m * x1 
04292009, 12:56 PM  #3 
Overdoses result in death
Join Date: Jan 2007
Posts: 2,365

Okay, that fixes the accuracy PERFECTLY. Now all I need is a howtoconfineintoboxalongtheyaxes.
__________________ 
04302009, 06:55 AM  #4 
Overdoses result in death
Join Date: Jan 2007
Posts: 2,365

Bump.
EDIT! Explanatory diagram attached. Last edited by TideArc Ephemera : 04302009 at 11:34 AM. 
Thread Tools  Search this Thread 

