Basically I need the Marine to face the "safest" place, so that later the angle that was used to make the Marine face this position will be very very useful to implement a kiting bot. The factors that will affect where the Marine is facing:
- Number of Zergling(s)
- Position of Zergling(s)
- Distance between Zergling(s) and the Marine (ignore this as a start)
Hi, Trieva, thanks for your response. Unfortunately Im not too good at using this map editor. Actually I was doing this earlier and I sort of gave up very quickly as I didn't know how to continue. (I use GUI btw)
This only useful action I found was "Make Unit Face Angle". It makes a unit face an angle that you specify.
A function I found called "Facing angle of unit" gets the facing angle (in a real) of a unit.
What I found interesting was the "angle mechanics". In the terrain editor to change the rotation of any unit you specify an angle between 0 and 360 degrees. The function "Facing angle of unit", however, returns a value of between -180 and 180 degrees. Figured out using a simple trigger:
And the result is a marine looking at the left and gradually turning in anti-clockwise direction. Here's a simple visualisation I made from what I understand:
Here is the trigger Change Marine Angle I made but it doesn't work.
Basically everything is already working correctly and well set, just that I don't know what to set the variable "angle" as and I'm trying to figure it out. Just need to think of some mathematical thing to achieve this...
By the way, this is the "Handle Marine Angle" action definition:
That's all I have. What I'm thinking is that the variable "nearby units angles" is completely useless and probably won't have any use in calculating the variable "angle". I think what I really need is a way to find the zergling's position relative to the marine in terms of angle. Like I need to find a way to get the number 0 when a Zergling is directly on the right of the Marine.
For the most dangerous facing you could use "make unit face point" and for the point "center of unit group". The unit group could be all nearby enemy units (units in region with alliance to player).
But now that I re-read the post, it looks like you want the least dangerous facing, so the opposite of above. It's been so long since I've taken geometry... Is there a good way to get the opposite of an angle?
It seems like it doesn't make sense, especially this line "Variable - Set angle = (Angle from (Position of (Picked unit)) to (Position of Marine))". Why am I setting the angle between the Zergling and the Marine as the angle for the Marine to turn?
Well, this is something I found that was interesting when I use the Angle between points function with point 1 as the position of Zergling and point 2 as the position of the marine:
Basically the Angle Between Points function sort of returns the opposite angle as compared to Make Unit Face Angle. So with this I sort of found the opposite of an angle. So the map works, but only with 1 zergling.
I don't know how to move on for more than 1 zergling, but I hope you guys will continue to give me advice. Thanks.
(See my post above for the explanation for the "(Angle from (Position of (Picked unit)) to (Position of Marine))" part.)
This is the compilation of my Marine's behaviour:
As you can see, the Marine is acting very strangely when there are 3 Zerglings, but perfect when there are 2 Zerglings. Would appreciate it if someone can find a solution to the Marine's strange behaviour when there are 3 Zerlings.
I'm not sure if this is better than the previous code (see previous post). It seems less glitchy when there are more than 2 zerglings but there are still a couple of glitches to fix. In your opinion, which code is preferred, the code in this post, or the code in the previous post?
The unit custom value was unnecessary, I thought that I would need it in future.
Basically the zerglings' opposite angles are the safe angles for each individual zergling. So I divide by the number of zerglings to get the average of these safe angles, and the marine will face this average angle (which is, in most cases, the safest angle)
Maybe it's easier to see visually:
By the way, by identifying the safe angle using my method, I came up with this little marine bot. Not the best one though, but still quite impressive. Attached below:
After thinking about it for a while, I think I need to change the equation to something else that is more accurate and reliable, especially for more than 2 zerglings. For more than 2 zerglings, there are many unexpected things that can happen. For example:
That's just one example. There are many other glitches when there are more than 2 nearby zerglings.
I just saw your new post. I think that changing the equation is still the way to go.
Could you elaborate on "divide the angles around the marine to a certain number of equal spaces and see which zerglings fall into these spaces."? I don't quite understand it, maybe a pic?
Will work on it maybe tomorrow. I made a video featuring my marine bot ()
The strange thing that happens everytime I run 15 Marines vs 50 Zerglings is that sometimes the Marines win by a narrow margin, sometimes the Zerglings win by a narrow margin, and a few times, the Zerglings win very one-sidedly. So that's a bit odd.
What if you did a loop, 0 to 359, and if you draw a line out from the marine at that angle and there is no Zergling at that location, increment a temporary counter. You will then simply find the maximum value of consecutive "safe angles" and use the middle degree angle as the safe angle.
Sorry, can't open up the editor at the moment to write this out, but it would solve the proper angle for all of the pictured Zerglings above.
For example, below the safe angle would be 37.5 degrees because there were 107 consecutive "safe angles" where there were no Zerglings (and I know that number isn't exact, because more than just one degree line would intersect with the Zergling), and half of that is 53.5, but you'd have to subtract 16 from that because the "safe angle" started at 344 and ended at 91, and voila, 37.5 degrees, now the marine should be facing the safest angle.
If you are concerned this is too taxing (which it might be) you could always increase the step, just make sure you don't increase it to the point that you miss some Zerglings!
Thanks for the advice. I know how to find the angles of the zerglings (btw, angles are from -180 to 180, not 0 to 360), I don't think I need a loop for that. But indeed it's a good idea to find the largest difference.
I'm trying to do it noww, but I'm not exactly sure how.
Might be able to combine my idea with some of the others. Since you can't make non circle/rectangular regions, you might be able to use negative regions to check the different areas around the marine, and see which has the least enemies.