I'd like to create an ability, which creates a unit which will have a "chain" or a beam, which connects to the caster, dealing damage every second to any enemy unit it crosses. I can't really see how this should be done. (2 moving units with a beam between them, dealing damage to enemy units hit)
I know it would be quite complicated, but I hope it could be done. Is it possible in data, or should I try with triggers instead.
If it was a static beam with a fixed distance, I'd use a Create Persistant effect which would launch a search on all the locations, but I can't figure out how to make it work between two moving targets, that can both move further and closer from eachother.
I would just trigger it.
Keep in mind that trigger searches use the center of a unit to find a unit, data searches find them with the unit's radius. You would just create a bigger search that is capable of finding all units in a circle in the center of both units with a radius of half of the distance between the units (so you search in a circle between both units) and then you calculate the distance to the line between the two points with math.
It might be possible with triggers using some validator to check for units within a certain angle of one unit and another.
With triggers I would strongly recommend performing only 1 area search (which includes all units possibly hit by the chain) and then filtering it for units within the line of the chain. This will probably be a lot more efficient and scale better than multiple searches in a line.
Quote:
Behold, math implemented in sc2.
You really sure it is faster this way than using points? Especially if you use the hidden Galaxy point operators for vector addition/subtraction?
You test if a distance is equal to 0. That stage could be optimized to check if both X and Y is equal to zero (avoids multiplications). This is because the summation of squares will only be 0 if all of the parts that are squared are 0 since anything not 0 squared is greater than 0.
Square product is used twice? Cached results probably faster.
Comments, unintelligible... I am pretty sure if you submitted that to any credible mathematics institute you would fail purely because you gave no idea of what you were doing. For example, why the conditional statements?
Surely the solution would be the length of the perpendicular to the line that runs to the given point?
I've cleaned up the program flow a bit, cached everything that would be calculated multiple times within a branch, tweaked the borders to use the shorter calculation when the projected point and the line point are on top of each other in the distance to line segment algorithm.
I did not create the algorithm or come up with the calculation approach, so I cannot explain what exactly is calculated within it. I merely ported it to SC2 and now attempted to create a hopefully efficient implementation in GUI.
As far as I can tell, the checks with the segment border are done via a comparison with a calculated multiplier.
The value appears to have the following relation:
projected line point with shortest distance = [vector from line point 1 to line point 2] * calculated multiplier
For the first check, I'm now only using the first part of the multiplier calculation as it only needs to know if the multiplier is less or equal to zero. The second check uses the complete multiplier and compares it to 1. If it is 1, the projected point is on the second line point. If the value is inbetween 0 and 1, it is between those points and then the vector from to the projected point on the line with the shortest distance is calculated out of the multiplier.
I didn't know about the point and vector operations in galaxy. I guess that the difference is negligible for SC2 maps. But you could run tests or implement this with it and compare the speed, if you really want to know that.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I'd like to create an ability, which creates a unit which will have a "chain" or a beam, which connects to the caster, dealing damage every second to any enemy unit it crosses. I can't really see how this should be done. (2 moving units with a beam between them, dealing damage to enemy units hit)
I know it would be quite complicated, but I hope it could be done. Is it possible in data, or should I try with triggers instead.
If it was a static beam with a fixed distance, I'd use a Create Persistant effect which would launch a search on all the locations, but I can't figure out how to make it work between two moving targets, that can both move further and closer from eachother.
Any suggestions? I'd be happy to hear them :D
Invisible missiles or just triggers...
I would just trigger it.
Keep in mind that trigger searches use the center of a unit to find a unit, data searches find them with the unit's radius. You would just create a bigger search that is capable of finding all units in a circle in the center of both units with a radius of half of the distance between the units (so you search in a circle between both units) and then you calculate the distance to the line between the two points with math.
It might be possible with triggers using some validator to check for units within a certain angle of one unit and another.
With triggers I would strongly recommend performing only 1 area search (which includes all units possibly hit by the chain) and then filtering it for units within the line of the chain. This will probably be a lot more efficient and scale better than multiple searches in a line.
You really sure it is faster this way than using points? Especially if you use the hidden Galaxy point operators for vector addition/subtraction?
You test if a distance is equal to 0. That stage could be optimized to check if both X and Y is equal to zero (avoids multiplications). This is because the summation of squares will only be 0 if all of the parts that are squared are 0 since anything not 0 squared is greater than 0.
Square product is used twice? Cached results probably faster.
Comments, unintelligible... I am pretty sure if you submitted that to any credible mathematics institute you would fail purely because you gave no idea of what you were doing. For example, why the conditional statements?
Surely the solution would be the length of the perpendicular to the line that runs to the given point?
@ImperialGood: Go
How is this version which includes a test map?
I've cleaned up the program flow a bit, cached everything that would be calculated multiple times within a branch, tweaked the borders to use the shorter calculation when the projected point and the line point are on top of each other in the distance to line segment algorithm.
I did not create the algorithm or come up with the calculation approach, so I cannot explain what exactly is calculated within it. I merely ported it to SC2 and now attempted to create a hopefully efficient implementation in GUI.
As far as I can tell, the checks with the segment border are done via a comparison with a calculated multiplier.
The value appears to have the following relation:
projected line point with shortest distance = [vector from line point 1 to line point 2] * calculated multiplier
For the first check, I'm now only using the first part of the multiplier calculation as it only needs to know if the multiplier is less or equal to zero. The second check uses the complete multiplier and compares it to 1. If it is 1, the projected point is on the second line point. If the value is inbetween 0 and 1, it is between those points and then the vector from to the projected point on the line with the shortest distance is calculated out of the multiplier.
I didn't know about the point and vector operations in galaxy. I guess that the difference is negligible for SC2 maps. But you could run tests or implement this with it and compare the speed, if you really want to know that.