for the map i am developing, i am trying to get a zealot to attack a ground critter, and with the result, the critter accelerates in the direction away from how it was hit.
I cannot in the slightest figure out how to do this.
any help would be greatly appreciated! :)
edit:/ what i have done is ive made it possible for hte unit to be attacked and that he never dies, however when it is attacked it just sits there, when i move beside it without attacking it however, the unit moves away like it normally would
What you want to do should look something like this. Of course, you'll probably want the zealot and the critter to be variables and possibly the distance too. Also, you'd have to edit the health of the critter so it does not die in one hit, or the trigger won't do anything.
Except the trigger, I only changed a few things in the data editor. I removed the wander behavior from the Lyote, gave it 1000 life and a high regen rate.
Can't you go into the Data Editor and set the critter to flee. I think it's called "Acquire Target" or something similar but, anyway, you can set it to flee.
Love the editor, so many ways to do the same thing, and none of them wrong... usually. :-p
I picked my way because it makes the unit run away from whoever is attacking it regardless of the current facing, some units might shoot without turning, some may turn after the shot if fired (dunno when "attacked" trigger, impact or shot fired).
The drawback of my way (fixable of course), would be that the distance is calculated from the attacking unit.
Klishu's way is probably the easiest way, but with less control of the distance it flees.
Try them all and see which feels best for your map. :)
Can't you go into the Data Editor and set the critter to flee. I think it's called "Acquire Target" or something similar but, anyway, you can set it to flee.
how do i go about doing this?
i have been searching through the data editor but cant find it.
For using hte trigger, my issue i have found is that you need to choose a unit from the map, but my units appear after a time limit, so they arent actually visual to be chosen from an area.
You can find it under "Behavior - Behaviors+" add "Critter Wander".
But if you want any sort of control over how the unit flees (it will run away even if you just move near him with the wander behavior), you should make a trigger that orders the unit around when hit.
So I'm having a similar problem. I have a trigger that's more or less exactly what Berrala wrote above (if attacked, move to point x amount from triggering unit, polar offset by angle between attacking unit and triggering unit). It's just not doing anything at all. My theory was that another movement-related trigger was messing with it, but on disabling those other triggers I still had the same problem.
I had forgotten to disable the wander behavior, which was giving me problems. Looks like it's working now. I'm still having a little issue, though. Maybe somebody will have a creative way to deal with it. I'm trying to implement this behavior for a bunch of cows so that can be herded. If a unit is near the edge of a corral (or up against any other obstacle) the movement order will often be to a point outside of the corral. This means that rather than moving away from the attacker, the unit will take a potentially long path around the obstacle. I can think of two potential ways to get around this, but I don't really know how to do either of them. The first would be to somehow check the path to the selected point and see how long it is. If it's a certain amount longer than offset distance of the move order, the movement would be canceled. I can't seem to find any to return a pathing distance rather than an absolute distance thought. The other potential solution would be to use an ability other than move that would be set up so the unit would just move in a certain direction for a certain time, rather than move targeting a point, but I really have no idea how to go about this. (are there any abilities already like this?)
Edit:
Apparently there's a function that returns the pathing cost between two points. I'll see if I can get it to work and report back.
I've done that before in another map. I'll paste the relevant parts of that trigger here. Most of my variables are named to make sense when I (you) read the code. But if something is unclear, ask away.
LocalVariablesBirdspath=(DistancebetweenPlayer[x].Current Position and Rally Click) <Real>
offset = 0.0 <Real>
Actions
General - While (Conditions) are true, do (Actions)
Conditions
offset <= Birds path
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
((Player[x].Current Position offset by offset towards Rally Click) is passable) == false
Then
Variable - Set Rally Click = Player[x].Current Position
Unit - Order Player[x].Hero to ( Set Next Move targeting Player[x].Current Position) (Replace Existing Orders)
Variable - Set offset = Birds path
Else
Variable - Modify offset: + 0.1
When an obstacle is found I want my unit to stay still, but you'll want to change the new order to target the current position on the offset - 0.1 since that was the last position that was clear.
Afterwards, I set the offset to Birds path so that the while loop ends and doesn't check any more.
So this is what I hacked together, but it's still not working. Initially the trigger was timing out, so I added the tries counter and a quick .1 second wait for good measure. I see the trigger firing in the debugger, but my cows aren't moving (neither the passive ones nor the ones already in their herd routine). If you see any errors or have any ideas, I'd love to hear! My only thought is that maybe the pathing cost is in different units or on a different scale than the actual distance. I'll see what happens if the allowable pathing cost is a much larger number. Edit: I set the limit for pathing cost to 80 and still got nothing, so it doesn't seem like this is the problem.
Edit: Oops, I seem to have kept typing a bit much. Ah well, I'll leave it anyway even though most of it is not really needed.
So... as far as I cal tell from you trigger you are:
Running the trigger when any unit owned by player 9 (the cows I assume) get close to a specific marine.
Logically, this feels backwards. It should be the marine that enters within a distance from a cow. Doesn't really matter here though.
The event may cause a problem if the marine manages to stay within the distance of the cow when it tries to run away, the trigger will not fire again until the marine moves outside the radius and then closer again.
Distance between cow and marine... tried < 4
Considering the content of the lop, the first condition seems ok combined with the wait 0.1. It will eventually finish. You are trying to make the trigger last until the cow is outside of the triggering range to avoid the problem I had concerns about in the event. However, if tries exceed 4, this till end the loop before the cow gets far enough away. You might end up having to make the event a periodic trigger instead since when cows are pressed against an obstacle, the cows cannot get outside of the range they want to.
Variable - Set PathingCost
I hate the pathing cost function. Because it returns an integer and not a real value, it is very inaccurate. Your pathing cost might be 4.4, 3.9, 4,9. I'm not sure exactly how these numbers are rounded, but they are being rounded, which is bad. Distance between points, however, returns a real number making it even harder to make a good comparison.
You case, you are checking a point 3 distance away and then making sure it's pathing cost does not exceed 5. Should work, even if we take the inaccuracy into account. The cow will take small detours but not move around large obstacles.
The problem as I see it is that tries < 4 really does nothing. I assume you added this to make sure the trigger ends when the cow gets stuck on something, but why count to 4? Just do a boolean variable "cow got stuck" and set it to true when the trigger should be aborted (side note, use "modify x: +1" instead of "set x = x + 1" )
Ok, now I've simply been testing and writing my reactions and thoughts, but basically your trigger works. I entered your trigger exactly as you wrote it into my test map and things work well. You say that it does not work at all for you? The only thing I can think of is that your cows are not actually owned by player 9? Then the event would fire. Or maybe I made a mistake when I copied your code and corrected something without noticing.
It should work, kind of and your only problem is making the trigger run again even when the marine and cow stays close to each other.
A way to fix this would be to remake your trigger into a "New Action Definition" with two parameters (the marine and the cow). Replace all references to your marine and cow to these parameters.
Now, make a new, periodic event trigger that runs every 0.5 seconds or so. "Pick each unit (cow) on the map and do actions" If picked unit close to marine... run the custom action with your marine and the picked unit (cow).
If you need help making a custom action, let me know.
Edit 2:
Ah whatever, it was an easy change after I already had your entire trigger in my map. There was no real need to make a custom action for this, but it looks good and you can easily use it for multiple units like this, just add whatever units you wanna check in the periodic trigger.
Now, since the Herd action runs automatically every 0.5 seconds, you don't have to keep the code that tried to make sure that the Cow exited the herd range since the triggers will run and check for distance permanently (and without time-out's or warnings since the trigger starts over instead of running an infinite loop). I kept it in the map example I posted since I didn't want to change too much. I'm sure you can figure out what parts are not needed.
The example you attached is pretty much exactly what I want. For some reason, I still can't get it to work in my map though. Maybe I made some change to the cow unit that's interrupting things?
Edit: Got it working now! I think one of my conditions was calling for a triggering unit after I had changed the trigger to periodic event, though I can't find the error in the code below.
Anyhow, here's the current version of my triggers:
Hi,
for the map i am developing, i am trying to get a zealot to attack a ground critter, and with the result, the critter accelerates in the direction away from how it was hit.
I cannot in the slightest figure out how to do this.
any help would be greatly appreciated! :)
edit:/ what i have done is ive made it possible for hte unit to be attacked and that he never dies, however when it is attacked it just sits there, when i move beside it without attacking it however, the unit moves away like it normally would
What you want to do should look something like this. Of course, you'll probably want the zealot and the critter to be variables and possibly the distance too. Also, you'd have to edit the health of the critter so it does not die in one hit, or the trigger won't do anything.
thanks for the quick reply,
for (attacking unit), do you mean the area that says "Value 1:"
okay i have done everything as shown, but for some reason the trigger doesnt want to work and the critter sits there when i attack it
It works in my minimalistic test environment.
Except the trigger, I only changed a few things in the data editor. I removed the wander behavior from the Lyote, gave it 1000 life and a high regen rate.
event->If "critter" is attacked
variable->attackAngle - <real> = 0
action-> issue order move to critter with polar offset for (range) with angle=attackAngle
Forgot a step in actions. Set attackAngle to facing angle of attacking unit. Do this before your move order
thx guys ill give that a try
im gone for 5 days after work today though, so i may not be able to try it until im back unfortunately
Can't you go into the Data Editor and set the critter to flee. I think it's called "Acquire Target" or something similar but, anyway, you can set it to flee.
Love the editor, so many ways to do the same thing, and none of them wrong... usually. :-p
I picked my way because it makes the unit run away from whoever is attacking it regardless of the current facing, some units might shoot without turning, some may turn after the shot if fired (dunno when "attacked" trigger, impact or shot fired).
The drawback of my way (fixable of course), would be that the distance is calculated from the attacking unit.
Klishu's way is probably the easiest way, but with less control of the distance it flees.
Try them all and see which feels best for your map. :)
how do i go about doing this?
i have been searching through the data editor but cant find it.
For using hte trigger, my issue i have found is that you need to choose a unit from the map, but my units appear after a time limit, so they arent actually visual to be chosen from an area.
You can find it under "Behavior - Behaviors+" add "Critter Wander".
But if you want any sort of control over how the unit flees (it will run away even if you just move near him with the wander behavior), you should make a trigger that orders the unit around when hit.
So I'm having a similar problem. I have a trigger that's more or less exactly what Berrala wrote above (if attacked, move to point x amount from triggering unit, polar offset by angle between attacking unit and triggering unit). It's just not doing anything at all. My theory was that another movement-related trigger was messing with it, but on disabling those other triggers I still had the same problem.
So... how does your trigger look? (copy as text, paste here in [code] tags)
I had forgotten to disable the wander behavior, which was giving me problems. Looks like it's working now. I'm still having a little issue, though. Maybe somebody will have a creative way to deal with it. I'm trying to implement this behavior for a bunch of cows so that can be herded. If a unit is near the edge of a corral (or up against any other obstacle) the movement order will often be to a point outside of the corral. This means that rather than moving away from the attacker, the unit will take a potentially long path around the obstacle. I can think of two potential ways to get around this, but I don't really know how to do either of them. The first would be to somehow check the path to the selected point and see how long it is. If it's a certain amount longer than offset distance of the move order, the movement would be canceled. I can't seem to find any to return a pathing distance rather than an absolute distance thought. The other potential solution would be to use an ability other than move that would be set up so the unit would just move in a certain direction for a certain time, rather than move targeting a point, but I really have no idea how to go about this. (are there any abilities already like this?)
Edit: Apparently there's a function that returns the pathing cost between two points. I'll see if I can get it to work and report back.
I've done that before in another map. I'll paste the relevant parts of that trigger here. Most of my variables are named to make sense when I (you) read the code. But if something is unclear, ask away.
When an obstacle is found I want my unit to stay still, but you'll want to change the new order to target the current position on the offset - 0.1 since that was the last position that was clear.
Afterwards, I set the offset to Birds path so that the while loop ends and doesn't check any more.
So this is what I hacked together, but it's still not working. Initially the trigger was timing out, so I added the tries counter and a quick .1 second wait for good measure. I see the trigger firing in the debugger, but my cows aren't moving (neither the passive ones nor the ones already in their herd routine). If you see any errors or have any ideas, I'd love to hear! My only thought is that maybe the pathing cost is in different units or on a different scale than the actual distance. I'll see what happens if the allowable pathing cost is a much larger number. Edit: I set the limit for pathing cost to 80 and still got nothing, so it doesn't seem like this is the problem.
Edit: Oops, I seem to have kept typing a bit much. Ah well, I'll leave it anyway even though most of it is not really needed.
So... as far as I cal tell from you trigger you are:
Running the trigger when any unit owned by player 9 (the cows I assume) get close to a specific marine.
Logically, this feels backwards. It should be the marine that enters within a distance from a cow. Doesn't really matter here though.
The event may cause a problem if the marine manages to stay within the distance of the cow when it tries to run away, the trigger will not fire again until the marine moves outside the radius and then closer again.
Distance between cow and marine... tried < 4
Considering the content of the lop, the first condition seems ok combined with the wait 0.1. It will eventually finish. You are trying to make the trigger last until the cow is outside of the triggering range to avoid the problem I had concerns about in the event. However, if tries exceed 4, this till end the loop before the cow gets far enough away. You might end up having to make the event a periodic trigger instead since when cows are pressed against an obstacle, the cows cannot get outside of the range they want to.
Variable - Set PathingCost
I hate the pathing cost function. Because it returns an integer and not a real value, it is very inaccurate. Your pathing cost might be 4.4, 3.9, 4,9. I'm not sure exactly how these numbers are rounded, but they are being rounded, which is bad. Distance between points, however, returns a real number making it even harder to make a good comparison.
You case, you are checking a point 3 distance away and then making sure it's pathing cost does not exceed 5. Should work, even if we take the inaccuracy into account. The cow will take small detours but not move around large obstacles.
The problem as I see it is that tries < 4 really does nothing. I assume you added this to make sure the trigger ends when the cow gets stuck on something, but why count to 4? Just do a boolean variable "cow got stuck" and set it to true when the trigger should be aborted (side note, use "modify x: +1" instead of "set x = x + 1" )
Ok, now I've simply been testing and writing my reactions and thoughts, but basically your trigger works. I entered your trigger exactly as you wrote it into my test map and things work well. You say that it does not work at all for you? The only thing I can think of is that your cows are not actually owned by player 9? Then the event would fire. Or maybe I made a mistake when I copied your code and corrected something without noticing.
It should work, kind of and your only problem is making the trigger run again even when the marine and cow stays close to each other.
A way to fix this would be to remake your trigger into a "New Action Definition" with two parameters (the marine and the cow). Replace all references to your marine and cow to these parameters.
Now, make a new, periodic event trigger that runs every 0.5 seconds or so. "Pick each unit (cow) on the map and do actions" If picked unit close to marine... run the custom action with your marine and the picked unit (cow).
If you need help making a custom action, let me know.
Edit 2:
Ah whatever, it was an easy change after I already had your entire trigger in my map. There was no real need to make a custom action for this, but it looks good and you can easily use it for multiple units like this, just add whatever units you wanna check in the periodic trigger.
Now, since the Herd action runs automatically every 0.5 seconds, you don't have to keep the code that tried to make sure that the Cow exited the herd range since the triggers will run and check for distance permanently (and without time-out's or warnings since the trigger starts over instead of running an infinite loop). I kept it in the map example I posted since I didn't want to change too much. I'm sure you can figure out what parts are not needed.
The example you attached is pretty much exactly what I want. For some reason, I still can't get it to work in my map though. Maybe I made some change to the cow unit that's interrupting things?
Edit: Got it working now! I think one of my conditions was calling for a triggering unit after I had changed the trigger to periodic event, though I can't find the error in the code below.
Anyhow, here's the current version of my triggers:
Then the Flee Action: