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

Making a Unit Leap Towards a Point

Status
Not open for further replies.
Level 5
Joined
Jan 5, 2008
Messages
145
My idea is once a unit is attacked from a certain angle another unit will leap towards him and kill him. I did all the math on paper and It all makes sense to me so I assumed I'm doing something wrong with how I have everything set up. Once the unit attacks and the trigger fires I want him to move really fast towards the attacked unit and rise in height once it gets directly on top of the unit it's height will drop to 0 and the attacked unit will die instantly with some blood effects. Right now the attacking unit just teleports around randomly and it looks really wonky.

Attached is what the math as I see it in my head.

Am I doing something wrong? I don't think the math is wrong but I also may have the offset wrong. Also how much more complicated would it be to make the height into an arc? I know you would need an 2d dimension expression with the roots being The point of the Attacked unit and Attacking unit but I would need some advice setting that up.

  • Instant Death
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Timber Wolf
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Facing of (Attacking unit)) Less than or equal to ((Facing of (Attacked unit)) + 10.00)) and ((Facing of (Attacking unit)) Greater than or equal to ((Facing of (Attacked unit)) - 10.00))
        • Then - Actions
          • Set TempInt2 = (Integer((Distance between (Position of (Attacked unit)) and (Position of (Attacking unit)))))
          • For each (Integer A) from 1 to 10, do (Actions)
            • Loop - Actions
              • Set TempInt = (Integer A)
              • Set TempPoint = (Position of (Attacked unit))
              • Set TempPoint2 = (TempPoint offset by ((Real(TempInt2)) - (Real(TempInt))) towards (Degrees((Facing of (Attacked unit)))) degrees)
              • Animation - Change (Attacking unit) flying height to ((Current flying height of (Attacking unit)) + (Real(TempInt))) at 0.02
              • Sound - Play Wolf1 <gen> at 100.00% volume, located at TempPoint with Z offset 0.00
              • Unit - Move (Attacking unit) instantly to TempPoint2
              • Wait 0.04 seconds
          • Wait 0.04 seconds
          • Unit - Kill (Attacked unit)
          • Unit - Move (Attacking unit) instantly to TempPoint
          • Animation - Change (Attacking unit) flying height to 0.00 at 0.00
          • Special Effect - Create a special effect at (Position of (Attacked unit)) using Objects\Spawnmodels\Human\HumanBlood\HumanBloodKnight.mdl
          • Animation - Play (Attacking unit)'s spell slam animation
          • Special Effect - Destroy (Last created special effect)
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: call RemoveLocation(udg_TempPoint2)
        • Else - Actions
Thanks in advance!
 

Attachments

  • math.png
    math.png
    17.4 KB · Views: 160
Last edited by a moderator:
Remove the points inside the integer loop, not outside. It creates leaks since you overwrite it 9 times. Also, store anything you use twice or more into a variable, because variables are faster than functions.

Additionally, do not use Integer A/B since they are buggy in nested loops; use your own integer variable. (You can name them A/B too!)

Lastly, the problem is most likely that you didn't store the unit facing into a variable before the loop - since it changes every 0.04 seconds, the wolf is thrown into different angles every time the loop runs. Variable storage can fix this.
 
Level 5
Joined
Jan 5, 2008
Messages
145
I did everything you suggested. To make it leak free and store the Facing angle, It works but instead of coming towards the unit from behind he teleports in front of him and derps out. Maybe I should remove the wait in the loop? Also the Height still isn't changing which is a little annoying. Should I force the angle of the villager to a the wolf while in the loop? Is the polar offset messing something up?

FSMYLjK.gif


  • Instant Death
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Timber Wolf
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Facing of (Attacking unit)) Less than or equal to ((Facing of (Attacked unit)) + 10.00)) and ((Facing of (Attacking unit)) Greater than or equal to ((Facing of (Attacked unit)) - 10.00))
        • Then - Actions
          • Set TempInt2 = (Integer((Distance between (Position of (Attacked unit)) and (Position of (Attacking unit)))))
          • Set TempInt3 = (Integer((Facing of (Attacked unit))))
          • For each (Integer TempInt) from 1 to 10, do (Actions)
            • Loop - Actions
              • Unit - Make (Attacked unit) face (Real(TempInt3)) over 0.00 seconds
              • Set TempPoint = (Position of (Attacked unit))
              • Set TempPoint2 = (TempPoint offset by ((Real(TempInt2)) - (Real(TempInt))) towards (Real(TempInt3)) degrees)
              • Animation - Change (Attacking unit) flying height to ((Current flying height of (Attacking unit)) + ((Real(TempInt)) x 3.00)) at 0.02
              • Sound - Play Wolf1 <gen> at 100.00% volume, located at TempPoint with Z offset 0.00
              • Unit - Move (Attacking unit) instantly to TempPoint2
              • Custom script: call RemoveLocation(udg_TempPoint)
              • Custom script: call RemoveLocation(udg_TempPoint2)
              • Wait 0.02 seconds
          • Wait 0.02 seconds
          • Set TempPoint = (Position of (Attacked unit))
          • Unit - Kill (Attacked unit)
          • Unit - Move (Attacking unit) instantly to TempPoint
          • Animation - Change (Attacking unit) flying height to 0.00 at 0.00
          • Special Effect - Create a special effect at TempPoint using Objects\Spawnmodels\Human\HumanBlood\HumanBloodKnight.mdl
          • Animation - Play (Attacking unit)'s spell slam animation
          • Special Effect - Destroy (Last created special effect)
          • Custom script: call RemoveLocation(udg_TempPoint)
        • Else - Actions
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
You should actually have at least 2 triggers. Using waits inside loops is a very bad idea. It's even the most likely reason why it's currently bugged. Instead you should keep an array of all currently jumping units and related data.
The first trigger should catch when a unit is supposed to start jumping and add it to the array.
The second trigger should constantly loop through all jumping units and do whatever periodic calculations you need.
 
Level 12
Joined
Oct 16, 2010
Messages
680
After u use wait, you won't be able to refer on (attacking unit) and neither the others

you have to store the units in variables as well on the beggining and as xonok told,

make a trigger thet starts on the attack event and after storing everything into variables
turn on the "loop" trigger.

for the arc you would like to use vectors instead
 
Last edited:
Level 4
Joined
Feb 28, 2014
Messages
70
I see many wrong things in your trigger. First of all you're converting Integers into Real, it's better if you just use Real variables.

Here's a trigger that may work

20gy6uc.jpg

2570qcp.jpg


Sorry for not adding the trigger in
  • tag but I'm to lazy to do it.
  • Try this and tell me if it worked fine, this is MUI so you won't get troubles with multiple wolves attaking at the same time
  • Edit: Btw, what is the attack range of the wolf? If the wolf is a melee unit it's pointless to make him leap when he's face-to-face to the target Unless he has a high attack range. Otherwise, I would recomend you to use a Unit issued an order targeting an object instead of Unit is attacked and add the distance as condition to trigger the leap.
  • Note: The distance condition I put on the trigger is not necessary, I was testing another event and I forgot to delete it :P
  • Edit2: Add
  • [trigger]Custom script: set udg_TriggeringUnit = null
  • Custom script: set udg_TargetedUnit = null
in the Else - Actions of the first trigger, I forgot it >.<
 
Last edited:
Level 5
Joined
Jan 5, 2008
Messages
145
WOW,Thank you for helping so much.. however.

How big should the arrays be? You said It's MUI and I see that but these arrays are going to hit a limit unless I remove from WolfID. Also I put it in and it kinda works. (The link is just a bug that was unexpected), It's just seems to be killing him too fast and not sliding into him, there should be a split second of the player panicing before death. Or should I increase the wolfs attack range.

http://i.imgur.com/ITsqnXm.gifv
ZAdnS37.gif
TLYBF00Z.jpg


  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • LeapDistanceTravel[LeapID] Greater than or equal to LeapDistanceMaxDistance[LeapID]
    • Then - Actions
      • Unit - Turn collision for (Picked unit) On
      • Animation - Change TriggeringUnit flying height to 0.00 at 0.00
      • Set TempPoint[1] = (Position of LeapTarget[LeapID])
      • Unit - Kill LeapTarget[LeapID]
      • Custom script: set udg_LeapTarget[udg_LeapID] = null
      • Special Effect - Create a special effect at TempPoint[1] using Objects\Spawnmodels\Human\HumanBlood\HumanBloodFootman.mdl
      • Set TempEff = (Last created special effect)
      • Custom script: call DestroyEffect(udg_TempEff)
      • Animation - Play (Picked unit)'s spell slam animation
      • Unit Group - Remove (Picked unit) from WolfLeapGroup
      • Custom script: call RemoveLocation(udg_TempPoint[1])
    • Else - Actions
Should I change this to turn on collision after the unit is dead? This would make it so it moves directly on top of his body.
 
Level 4
Joined
Feb 28, 2014
Messages
70
Well, how many wolves are in your map exactly? If they're constantly created then I don't think it could reach over 8000~ (I don't remember the array limit but it's more than 8k) In the case that you seriously need more than 8k, I'd recommend you Unit Indexer

You can try reducing flying height and setting a lower rate and it would be more realistic at the moment it jumps. When I tested it the wolf I used had 400 range so it jumped perfectly to the target but yes, it killed him before jumping which is kind of illogical (and it was also illogical that wolf having so much range :p), I think you can calculate a wait based on the time the wolf reach its target.

Edit: You can also try Melee/Ranged System to make wolves' attack to be ranged and become melee when they're near you. It would be helpful to create a true Leap, also is it necessary to kill the unit via trigger? You can also give to the wolf extra damage to 1-shoot the peasant
 
Level 5
Joined
Jan 5, 2008
Messages
145
I set the wolves range to 400 and got the exact result as the gif in my previous post. I've had to do something wrong, Maybe I should save this for a special wolf? I just wanted to make the player afraid to run away from the wolf as it's dangerous to turn your back to the enemy.

For how many wolves are on the map, it's all random I don't have any control of that. depending on the players could be 20~50. However when one dies another takes its place in the map.

After the trigger is done couldn't I just decrement the WolfID?

I'm just worried I'm going to put all this work into something no one will care about.

  • Instant Death
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Timber Wolf
    • Actions
      • Set TriggeringUnit = (Attacking unit)
      • Set TargetedUnit = (Attacked unit)
      • Set TempPoint[1] = (Position of TriggeringUnit)
      • Set TempPoint[2] = (Position of TriggeringUnit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between TempPoint[1] and TempPoint[2]) Less than or equal to 600.00
        • Then - Actions
          • Set TempReal[1] = ((Facing of TargetedUnit) + 15.00)
          • Set TempReal[2] = ((Facing of TargetedUnit) - 15.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Facing of TriggeringUnit) Less than or equal to TempReal[1]) and ((Facing of TriggeringUnit) Greater than or equal to TempReal[2])
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of TriggeringUnit) Equal to 0
                • Then - Actions
                  • Set WolfID = (WolfID + 1)
                  • Unit - Set the custom value of TriggeringUnit to WolfID
                  • Unit Group - Add TriggeringUnit to WolfLeapGroup
                  • Set LeapDistanceTravel[WolfID] = 0.00
                  • Set LeapDistanceMaxDistance[WolfID] = (Distance between TempPoint[1] and TempPoint[2])
                  • Set LeapAngle[WolfID] = (Facing of TriggeringUnit)
                  • Set LeapTarget[WolfID] = TargetedUnit
                  • Unit - Turn collision for TriggeringUnit Off
                  • Unit - Add Crow Form to TriggeringUnit
                  • Unit - Remove Crow Form from TriggeringUnit
                  • Animation - Change TriggeringUnit flying height to 150.00 at 300.00
                  • Trigger - Turn on Instant Death Loop <gen>
                  • Custom script: call RemoveLocation(udg_TempPoint[1])
                  • Custom script: call RemoveLocation(udg_TempPoint[2])
                  • Custom script: set udg_TriggeringUnit = null
                  • Custom script: set udg_TargetedUnit = null
                • Else - Actions
                  • Set TempID = (Custom value of TriggeringUnit)
                  • Unit Group - Add TriggeringUnit to WolfLeapGroup
                  • Set LeapDistanceTravel[WolfID] = 0.00
                  • Set LeapDistanceMaxDistance[WolfID] = (Distance between TempPoint[1] and TempPoint[2])
                  • Set LeapAngle[WolfID] = (Facing of TriggeringUnit)
                  • Set LeapTarget[WolfID] = TargetedUnit
                  • Unit - Turn collision for TriggeringUnit Off
                  • Unit - Add Crow Form to TriggeringUnit
                  • Unit - Remove Crow Form from TriggeringUnit
                  • Animation - Change TriggeringUnit flying height to 150.00 at 300.00
                  • Trigger - Turn on Instant Death Loop <gen>
                  • Custom script: call RemoveLocation(udg_TempPoint[1])
                  • Custom script: call RemoveLocation(udg_TempPoint[2])
            • Else - Actions
        • Else - Actions
          • Custom script: set udg_TriggeringUnit = null
          • Custom script: set udg_TargetedUnit = null
  • Instant Death Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in WolfLeapGroup) Greater than or equal to 1
        • Then - Actions
          • Unit Group - Pick every unit in WolfLeapGroup and do (Actions)
            • Loop - Actions
              • Set LeapID = (Custom value of (Picked unit))
              • Set LeapLoc = (Position of (Picked unit))
              • Set LeapMovement = (LeapLoc offset by 35.00 towards LeapAngle[LeapID] degrees)
              • Unit - Move (Picked unit) instantly to LeapMovement
              • Custom script: call RemoveLocation(udg_LeapLoc)
              • Custom script: call RemoveLocation(udg_LeapMovement)
              • Set LeapDistanceTravel[LeapID] = (LeapDistanceTravel[LeapID] + 35.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LeapDistanceTravel[LeapID] Greater than or equal to (LeapDistanceMaxDistance[LeapID] / 2.00)
                • Then - Actions
                  • Unit - Add Crow Form to TriggeringUnit
                  • Unit - Remove Crow Form from TriggeringUnit
                  • Animation - Change TriggeringUnit flying height to 0.00 at 50.00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • LeapDistanceTravel[LeapID] Greater than or equal to LeapDistanceMaxDistance[LeapID]
                • Then - Actions
                  • Unit - Turn collision for (Picked unit) On
                  • Animation - Change TriggeringUnit flying height to 0.00 at 0.00
                  • Set TempPoint[1] = (Position of LeapTarget[LeapID])
                  • Unit - Kill LeapTarget[LeapID]
                  • Custom script: set udg_LeapTarget[udg_LeapID] = null
                  • Special Effect - Create a special effect at TempPoint[1] using Objects\Spawnmodels\Human\HumanBlood\HumanBloodFootman.mdl
                  • Set TempEff = (Last created special effect)
                  • Custom script: call DestroyEffect(udg_TempEff)
                  • Animation - Play (Picked unit)'s spell slam animation
                  • Unit Group - Remove (Picked unit) from WolfLeapGroup
                  • Custom script: call RemoveLocation(udg_TempPoint[1])
                • Else - Actions
        • Else - Actions
          • Trigger - Turn off (This trigger)
 
Level 4
Joined
Feb 28, 2014
Messages
70
Triggering Unit is Attacked Unit. Set the angle to Facing of Attacking Unit.

But...

  • Set TriggeringUnit = (Attacking unit)
About the WolfID... Yes, you can. After the loop ends you can pick all wolves in the map and set their custom value to 0 and then you can set WolfID to 0.

EDIT: I found the error

  • Set TempPoint[1] = (Position of TriggeringUnit)
  • Set TempPoint[2] = (Position of TriggeringUnit)
You set 2 points with the same position, that'd be a problem.
 
Level 5
Joined
Jan 5, 2008
Messages
145
OH DUH! How did I miss that! :plol:

Fixing that brings it to this, The wolf's jump is almost perfect! I love how terrifying it is, I'll have to mess with the animations,speed, height, and special effects till I think it is perfect. Thank you so much! Only question is how do I get him to come down? I thought the trigger did that in the 2nd part of the loop.

eglfjsk.gif
 
Level 5
Joined
Jan 5, 2008
Messages
145
Because the references in the loop are to the TriggeringUnit variable, not Picked Unit.

I still suggest Dynamic Indexing be used.

I will put this in, This seems incredibly useful. This is pretty much the only thing that will require indexing at the moment. Other things I'm interested in is a backpack/inventory system. I'm a pretty crap creator even after all these years lurking here.
 
Level 12
Joined
Oct 16, 2010
Messages
680
as I told you before. Learn to use vectors

Much smoother, easyer to manipulate when u get used to it:)

also , as some told u before. Increase the wolf attack range so then it will make much more sense:D even you can set condition if the wolf is near enough it wont jump at all, but its up to u.
 
Level 4
Joined
Feb 28, 2014
Messages
70
I also suggest what Xonok says, but you'll need to recode the ability, anyway you have to code by the way you know or it's easy for you (I don't considere a good idea to use Other's system when you don't know/understand how they work).

Also:

  • Animation - Change TriggeringUnit flying height to 0.00 at 0.00
In the loop you must use picked unit, that's why the wolf keeps flying.
 
Level 5
Joined
Jan 5, 2008
Messages
145
I would do this kind of ability based on the event "Any unit is issued an order". It's cleaner than using attacks.

Like a great Idea! I'll tinker with that. Isn't this just a slight change with replacing attacking unit with Ordered Unit and attacked unit as Target unit issued order?

Then I could just do a range check. This could look much better!

Thank you much everyone helping out a "new guy" :grin: These ideas are great.
 
Status
Not open for further replies.
Top