• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Math problem >.<

Status
Not open for further replies.
Skipped high-school, eh ?
Pythagoras.

Otherwise...
  • Set TempPoint1 = Conversion - Coordinates takes X1 & Y1
  • Set TempPoint2 = Conversion - Coordinates takes X2 & Y2
  • Set Angle = Angle Betwen points
Still I recomment Pythagoras...
 
Still I recomment Pythagoras...
You skipped school too much?
Pythagoras is not for angles. It is for length.

What you want is this:

bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
where
- x1 is the x of the initial location
- y1 is the y of the initial location
- x2 is the x of the final location
- y2 is the y of the final location

Put that in a custom script and you are in.
 
Skipped high-school, eh ?
Pythagoras.

Otherwise...
  • Set TempPoint1 = Conversion - Coordinates takes X1 & Y1
  • Set TempPoint2 = Conversion - Coordinates takes X2 & Y2
  • Set Angle = Angle Betwen points
Still I recomment Pythagoras...

Nope, I forgot what I learnt XD

The idea is to not use 'Set point'. I already have X and Y values. I want to calculate the new point like you would in JASS and then use 'SetUnitPostition(unit,X,Y) and save their new XY values for the next loop'.

EDIT: It's actually for my meethook spell. It works now but I want to use the leaset possible processing power for those chains
 
bj_RADTODEG * Atan2(y2 - y1, x2 - x1)Put that in a custom script and you are in.
skipping high school... fine
skipping my posts... be carefull

EDIT:
@All-people-that-did-pay-attention-in-math-classes
Yes, Atan2 is a really stupid function.
It should be this:
bj_RADTODEG * Atan((y2 - y1) / (x2 - x1))

EDIT:
bj_RADTODEG = 360 / PI = 114.59155902616363175359630962821 (if anyone was ever going to use it outside the WE)
 
Thanks for your help but I still can't get it to work >.<
This is the old way and its working fine. Each piece of chain moves towards the next piece of chain without any problem
  • For each (Integer i) from 2 to MeatHLength[CValue], do (Actions)
    • Loop - Actions
      • -------- CURVE --------
      • Set MeatHCur = (Position of MeatHChain[i])
      • Set MeatHPrev = (Position of MeatHChain[(i - 1)])
      • Unit - Move MeatHChain[i] instantly to (MeatHCur offset by MeatHSpeed[CValue] towards (Angle from MeatHCur to MeatHPrev) degrees)
      • Custom script: call RemoveLocation(udg_MeatHCur)
      • Custom script: call RemoveLocation(udg_MeatHNext)
Here is the new 'more efficient way. Each chain's XY value is stored in an array so I don't need to use the 'set point = pos of unit' and destroy it afterwards
  • For each (Integer i) from 2 to MeatHLength[CValue], do (Actions)
    • Loop - Actions
      • -------- CURVE --------
      • Custom script: set udg_Temp_Real = bj_RADTODEG * Atan2(udg_MeatHY[udg_i] - udg_MeatHY[udg_i - 1], udg_MeatHX[udg_i] - udg_MeatHX[udg_i - 1])
      • Set MeatHX[MeatHChainCustom[i]] = (MeatHSpeed[CValue] x (Cos(Temp_Real)))
      • Set MeatHY[MeatHChainCustom[i]] = (MeatHSpeed[CValue] x (Sin(Temp_Real)))
      • Custom script: call SetUnitPosition(udg_MeatHChain[udg_i],udg_MeatHX[udg_MeatHChainCustom[udg_i]],udg_MeatHY[udg_MeatHChainCustom[udg_i]])
Suddenly the game is lagging really bad and the chain isn't visible anymore... Did I do something stupid?

EDIT: I know the old version has a location leak. I didn't noticed before I uploaded it :/
 
Ok I don't really want to submit the trigger because it has many leaks (that I am able to fix) and I got in trouble for doing that last time but I'll doing it anyway. just for clearance:
CValue = custom value of the meat hook's head
MeatHChainCustom = custom value of each piece of chain
Interval: 0.03

The spell works so there is no need to study the whole trigger. If something is unclear, feel free to ask
  • Meathook cast Copy
    • Events
      • Unit - A unit Starts the effect of an ability
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Meat Hook2
    • Actions
      • Custom script: if IsUnitGroupEmptyBJ(udg_MeatHHeads) == true then
      • Custom script: call EnableTrigger( gg_trg_Meathook_loop_Copy )
      • Custom script: endif
      • Set Temp_Unit = (Triggering unit)
      • Set Temp_Point = (Position of Temp_Unit)
      • Set Temp_Point2 = (Target point of ability being cast)
      • Set Temp_Real = (Angle from Temp_Point to Temp_Point2)
      • Custom script: call RemoveLocation(udg_Temp_Point2)
      • Unit - Create 1 Hook (Head) for (Owner of Temp_Unit) at Temp_Point facing Temp_Real degrees
      • Unit Group - Add (Last created unit) to MeatHHeads
      • Set Temp_Int = (Custom value of (Last created unit))
      • Set MeatHC[Temp_Int] = Temp_Unit
      • Set MeatHookTraveled[Temp_Int] = 0.00
      • Set MeatHLength[Temp_Int] = 0
      • Set MeatHT[Temp_Int] = No unit
      • Set MeatHLaunch[Temp_Int] = True
      • -------- CUSTOM PROPERTIES --------
      • Set MeatHDistance[Temp_Int] = 2500.00
      • Set MeatHSpeed[Temp_Int] = 20.00
      • Set MeatHDamage[Temp_Int] = 100.00
      • Set MeatHDamageLoop[Temp_Int] = 1.00
      • Set MeatHAoE[Temp_Int] = 75.00
      • Set MeatHChainRate[Temp_Int] = 100.00
      • -------- END PROPERTIES --------
      • Set Temp_Point2 = (Temp_Point offset by 120.00 towards Temp_Real degrees)
      • Unit - Move UDexUnits[Temp_Int] instantly to Temp_Point2
      • Set MeatHX[(Custom value of UDexUnits[Temp_Int])] = (X of Temp_Point2)
      • Set MeatHY[(Custom value of UDexUnits[Temp_Int])] = (Y of Temp_Point2)
      • Set MeatHLength[Temp_Int] = (MeatHLength[Temp_Int] + 1)
      • Unit Group - Add UDexUnits[Temp_Int] to MeatHChains
      • Set MeatHA[(Custom value of UDexUnits[Temp_Int])] = Temp_Int
      • Set MeatHB[(Custom value of UDexUnits[Temp_Int])] = MeatHLength[Temp_Int]
      • Custom script: call RemoveLocation(udg_Temp_Point2)
      • Custom script: call RemoveLocation(udg_Temp_Point)

  • Meathook loop Copy
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MeatHHeads and do (Actions)
        • Loop - Actions
          • Set MeatHHead = (Picked unit)
          • Set CValue = (Custom value of MeatHHead)
          • Set MeatHCLoc = (Position of MeatHC[CValue])
          • Set Temp_Point = (Position of MeatHHead)
          • -------- index chain into array --------
          • Unit Group - Pick every unit in MeatHChains and do (Actions)
            • Loop - Actions
              • Set Temp_Unit = (Picked unit)
              • -------- Pick chains that belongs to head --------
              • -------- 2D Array: A - fliter chains that belongs to head/spell --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MeatHA[(Custom value of Temp_Unit)] Equal to CValue
                • Then - Actions
                  • -------- 2D Array: B - index inside spell A --------
                  • Set MeatHChainCustom[MeatHB[(Custom value of Temp_Unit)]] = (Custom value of Temp_Unit)
                  • Set MeatHChain[MeatHB[(Custom value of Temp_Unit)]] = Temp_Unit
                • Else - Actions
          • Custom script: call DestroyGroup(GetLastCreatedGroup())
          • Set Temp_Real = (Distance between MeatHCLoc and (Position of MeatHChain[MeatHLength[CValue]]))
          • -------- ////ADD CHAINS//// --------
          • Custom script: if udg_Temp_Real > udg_MeatHChainRate[udg_CValue] then
          • Custom script: loop
          • Custom script: exitwhen udg_Temp_Real <= udg_MeatHChainRate[udg_CValue]
          • Set Temp_Real = (Temp_Real - MeatHChainRate[CValue])
          • Unit - Create 1 Chain (Dummy) for Neutral Passive at ((Position of MeatHChain[MeatHLength[CValue]]) offset by MeatHChainRate[CValue] towards (Angle from (Position of MeatHChain[MeatHLength[CValue]]) to MeatHCLoc) degrees) facing (Facing of MeatHHead) degrees
          • Set MeatHLength[CValue] = (MeatHLength[CValue] + 1)
          • Set Temp_Int = (Custom value of (Last created unit))
          • Unit Group - Add UDexUnits[Temp_Int] to MeatHChains
          • -------- 2D Array where A = Spell index (custom value/CValue) and B = index of chain inside spell (MeathHLength[]) --------
          • Set MeatHA[Temp_Int] = CValue
          • Set MeatHB[Temp_Int] = MeatHLength[CValue]
          • -------- End 2D Array --------
          • Set MeatHChain[MeatHLength[CValue]] = UDexUnits[Temp_Int]
          • Set MeatHX[Temp_Int] = (X of (Position of UDexUnits[Temp_Int]))
          • Set MeatHY[Temp_Int] = (Y of (Position of UDexUnits[Temp_Int]))
          • Custom script: endloop
          • -------- ////REMOVE CHAINS//// --------
          • Custom script: else
          • Custom script: loop
          • Unit - Remove MeatHChain[MeatHLength[CValue]] from the game
          • Set MeatHLength[CValue] = (MeatHLength[CValue] - 1)
          • Set Temp_Real = (Distance between MeatHCLoc and (Position of MeatHChain[MeatHLength[CValue]]))
          • Custom script: exitwhen udg_Temp_Real > udg_MeatHChainRate[udg_CValue]
          • Custom script: endloop
          • Custom script: endif
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • MeatHLaunch[CValue] Equal to True
            • Then - Actions
              • Unit - Create 1 Chain (Dummy) for Neutral Passive at ((Position of MeatHChain[MeatHLength[CValue]]) offset by MeatHSpeed[CValue] towards (Angle from (Position of MeatHChain[MeatHLength[CValue]]) to MeatHCLoc) degrees) facing (Facing of MeatHHead) degrees
              • Set MeatHLength[CValue] = (MeatHLength[CValue] + 1)
              • Unit Group - Add (Last created unit) to MeatHChains
              • -------- 2D Array where A = Spell index (custom value/CValue) and B = index of chain inside spell (MeathHLength[]) --------
              • Set MeatHA[(Custom value of (Last created unit))] = CValue
              • Set MeatHB[(Custom value of (Last created unit))] = MeatHLength[CValue]
              • -------- End 2D Array --------
              • Set MeatHChain[MeatHLength[CValue]] = (Last created unit)
              • Unit - Move MeatHHead instantly to ((Position of MeatHHead) offset by MeatHSpeed[CValue] towards (Facing of MeatHHead) degrees)
              • For each (Integer i) from 2 to MeatHLength[CValue], do (Actions)
                • Loop - Actions
                  • -------- CURVE --------
                  • Set MeatHCur = (Position of MeatHChain[i])
                  • Set MeatHNext = (Position of MeatHChain[(i - 1)])
                  • Unit - Move MeatHChain[i] instantly to (MeatHCur offset by MeatHSpeed[CValue] towards (Angle from MeatHCur to MeatHNext) degrees)
              • Set MeatHookTraveled[CValue] = (MeatHookTraveled[CValue] + MeatHSpeed[CValue])
              • Set Temp_Point2 = (Position of MeatHHead)
              • Set Temp_Group = (Units within MeatHAoE[CValue] of Temp_Point2 matching (((Matching unit) Not equal to MeatHC[CValue]) and (((Unit-type of (Matching unit)) Not equal to Chain (Dummy)) and ((Unit-type of (Matching unit)) Not equal to Hook (Head)))))
              • Custom script: call RemoveLocation(udg_Temp_Point2)
              • -------- Pick target --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Temp_Group is empty) Equal to False
                • Then - Actions
                  • Set MeatHT[CValue] = (Random unit from Temp_Group)
                  • Unit - Turn collision for MeatHT[CValue] Off
                  • Unit - Cause MeatHC[CValue] to damage MeatHT[CValue], dealing MeatHDamage[CValue] damage of attack type Normal and damage type Normal
                  • Set MeatHLaunch[CValue] = False
                • Else - Actions
              • Custom script: call DestroyGroup(udg_Temp_Group)
              • Custom script: if udg_MeatHookTraveled[udg_CValue] > udg_MeatHDistance[udg_CValue] then
              • Custom script: set udg_MeatHLaunch[udg_CValue] = false
              • Custom script: endif
            • Else - Actions
              • Unit - Move MeatHChain[MeatHLength[CValue]] instantly to ((Position of MeatHChain[MeatHLength[CValue]]) offset by MeatHSpeed[CValue] towards (Angle from (Position of MeatHChain[MeatHLength[CValue]]) to MeatHCLoc) degrees)
              • For each (Integer i) from 1 to MeatHLength[CValue], do (Actions)
                • Loop - Actions
                  • -------- CURVE --------
                  • Set Temp_Int = (MeatHLength[CValue] - i)
                  • Set MeatHCur = (Position of MeatHChain[Temp_Int])
                  • Set MeatHNext = (Position of MeatHChain[(Temp_Int + 1)])
                  • Unit - Move MeatHChain[Temp_Int] instantly to (MeatHCur offset by MeatHSpeed[CValue] towards (Angle from MeatHCur to MeatHNext) degrees)
              • Set Temp_Point2 = (Position of MeatHChain[1])
              • Custom script: call SetUnitX(udg_MeatHT[udg_CValue], GetLocationX(udg_Temp_Point2))
              • Custom script: call SetUnitY(udg_MeatHT[udg_CValue], GetLocationY(udg_Temp_Point2))
              • Custom script: call RemoveLocation(udg_Temp_Point2)
              • Unit - Cause MeatHC[CValue] to damage MeatHT[CValue], dealing MeatHDamageLoop[CValue] damage of attack type Normal and damage type Normal
              • -------- Removes last 'piece' of chain --------
              • -------- End spell --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (MeatHLength[CValue] Equal to 0) or ((MeatHC[CValue] is dead) Equal to True)
                • Then - Actions
                  • Unit - Turn collision for MeatHT[CValue] On
                  • Set MeatHT[CValue] = No unit
                  • Unit Group - Remove MeatHHead from MeatHHeads
                  • For each (Integer i) from 1 to MeatHLength[CValue], do (Actions)
                    • Loop - Actions
                      • Unit - Remove MeatHChain[i] from the game
                  • Custom script: if IsUnitGroupEmptyBJ(udg_MeatHHeads) == true then
                  • -------- Trigger gets disabled, therefore Temp_Point at the bottom won't be remove. --------
                  • Custom script: call RemoveLocation(udg_Temp_Point)
                  • Custom script: call DisableTrigger(GetTriggeringTrigger())
                  • Custom script: endif
                • Else - Actions
          • -------- Add aditional chains --------
          • Custom script: call RemoveLocation(udg_Temp_Point)
The below the 'curve' commend is where the chain actually moves. It keeps getting the location, calculate new location and destroy the location.

You will see that I assign a virtual X/Y location (MeatHX/Y) to the piece when I create it in the looping trigger. I want to use that and basic math to calculate the new loc and use 'SetUnitLoc(unit,x,y).
 
Last edited:
Status
Not open for further replies.
Back
Top