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

[Trigger] Instant move unit back when attacked

Status
Not open for further replies.
Level 3
Joined
Jun 17, 2015
Messages
53
Hi everyone, sorry for bothers you to read but i need to ask, i dont know whats wrong with my trigger

The Spell said:
When unit got attacked, it instantly move back 250 range from Attacking Unit

I did the trigger, but when units attacks, it moves chaos, foward, backward.... and i dont know what's wrong with my trigger :vw_sad:


  • Fade
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) has buff Fade ) Equal to (==) True
      • ((Attacking unit) belongs to an enemy of (Owner of (Attacked unit))) Equal to (==) True
    • Actions
      • Set AAReal = (Facing of (Attacking unit))
      • Set AALoc1 = (Position of (Attacked unit))
        • Do Multiple ActionsFor each (Integer A) from 1 to (250 / 50), do (Actions)
          • Loop - Actions
            • Set AALoc2 = (AALoc1 offset by (275.00 - (25.00 x (Real((Integer A))))) towards AAReal degrees)
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Terrain pathing at AALoc2 of type Walkability is off) Equal to (==) False
                • Then - Actions
                  • Unit - Move (Attacked unit) instantly to AALoc2
                  • Unit - Order (Attacked unit) to Attack (Attacking unit)
                • Else - Actions
                  • Do nothing
            • Custom script: call RemoveLocation(udg_AALoc2)
      • Custom script: call RemoveLocation(udg_AALoc1)
 
Level 25
Joined
Sep 26, 2009
Messages
2,377
I wouldn't use facing of (attacking unit) but instead get position of attacking unit, position of attacked unit and then get the angle between two points.
  • Actions
    • Set loc1 = *somewhere*
    • Set loc2 = *somewhere else*
    • Set angle = (Angle from loc1 to loc2)
Inside the loop, did you change it just now for test? Because if not, then it is useless to have the 250/50 calculation there, as it always returns 5, so why not simply make it loop from 1 to 5.
The loop itself executes all iterations almost immediately, hence you will probably notice the unit to move instantly away instead of gradually moving. For that you would need a trigger with 0.03 periodic event to mimic movement.

Also do note that your range calculation for the second location is 275 - 25*current_iteration_number.
Since you start at number 1 and go to number 5, you will actually move the unit closer to the attacker instead of away (basically 1st iteration moves unit to 275 - 25 = 250 range, while the 5th iteration moves the unit to 275 - 125 = 150 range).

Remove the "Do nothing" action, as it really does nothing but take processing power (you can leave the whole Else block blank - without any action).

As for the problem itself, it may be tied to the event "Unit is attacked" event. This event fires when unit starts attacking (=starts swinging sword/prepare to shoot arrow), not when the unit lands an attack.
 
Level 3
Joined
Jun 17, 2015
Messages
53
You should use multiple conditions in conditions panel. Now unit will move when attacked by all units with fade buff and all enemy units. As for other things, I have no idea what's wrong but I'm noob, so don't worry, someone else will know :D.

np bro, im still looking for errors now

@Nichilus: i havent changed the loop 250/50. My points are when unit swing weapons, unit with Fade buff will jump back 250 range and attack it. I think this is so simple, dont need to make an 0.03 time event = =
 
Level 25
Joined
Sep 26, 2009
Messages
2,377
i havent changed the loop 250/50.
Then you should really just change it from "For each var from 1 to (250/50)" to "For each var from 1 to 5", because that is the same, yet the game does not need to calculate what the result of (250/50) operation is.

My points are when unit swing weapons, unit with Fade buff will jump back 250 range and attack it. I think this is so simple, dont need to make an 0.03 time event = =
You misunderstand here. With what you have right now you will never reach a visually good-looking jump. The "For each" loop executes so fast that it is impossible for human eye to notice each iteration (execution speed around microseconds). So even if you move your unit bit by bit in each iteration of the loop, in the end all that human eye perceives is the effect of last iteration (the final movement of the unit).

tl;dr
What you want: A "jump back" movement
What you have: A "teleportation" away from enemy.

The average amount of pictures human eye can perceive is about 25-28 frames (=pictures) per second (FPS). Hence why I suggested you use a 0.03 periodic timer, because 28 fps is 1 frame every 0.035 second (1/28). If you move your unit every 0.03 seconds, you will see that it actually flies back, instead of just being teleported away.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
The average amount of pictures human eye can perceive is about 25-28 frames (=pictures) per second (FPS).
Humans can perceive well past 100 FPS, especially if the frame rate is irregular (eg changing from 30 to 60 FPS all the time). You can fool human eyes with lower frame rates if motion blur is applied since that imitates what our brains perceive as motion.

WC3 lacks motion blur and runs at 60 FPS so anything less than 60 FPS is easy to see. Although the difference between 33.3... FPS and 60 FPS is small enough to be bearable.
 
Level 3
Joined
Jun 17, 2015
Messages
53
Then you should really just change it from "For each var from 1 to (250/50)" to "For each var from 1 to 5", because that is the same, yet the game does not need to calculate what the result of (250/50) operation is.


You misunderstand here. With what you have right now you will never reach a visually good-looking jump. The "For each" loop executes so fast that it is impossible for human eye to notice each iteration (execution speed around microseconds). So even if you move your unit bit by bit in each iteration of the loop, in the end all that human eye perceives is the effect of last iteration (the final movement of the .

understood, i didnt know it moves unit 5 times cuz its instantly, well a 0.35 timer is same haha. Ty ill try.

WC3 lacks motion blur and runs at 60 FPS so anything less than 60 FPS is easy to see. Although the difference between 33.3... FPS and 60 FPS is small enough to be bearable.

tks for the info bro <3
 
Status
Not open for further replies.
Top