In the Starcraft 2 Editor, there are three standard types of regions: Circles, Rectangles, and Diamonds. These are very basic shapes and don't support rotations whatsoever. Here is how to make them work in that regard.
Overview
This function does not work by rotating the region. Instead, it rotates the checking point in relation to the pseudo-angle of an imaginary rotated region. The rotation is only applied to the checking point (in relation to the center of the region) and not to the region itself.This is much better on the CPU and takes a ton less math, is perfectly accurate, and uses the built in Point/Unit Is In Region (allowing for support of any regions built of as many of the standard shapes as you want). And, it's surprisingly simple.
On the left, the region is not actually rotated, only the point. On the right is the final product.
There will be two function when we are done that return booleans:
Point Is In Rotated Region
Unit Is In Rotated Region
Now, let's get started...
The Code and Theory
Basically, the required parameters are very similar to the standard "Point Is In Region", except we add one more parameter to the function: Angle. The reference point of the rotation is the regions center.
Center is the center of the region.
Point is the point we are testing to see if it's in the region.
WorkPoint is the final test point we calculated after rotating.
So, the trick:
1. Store the distance between Center and Pointdist
2. Store the angle between Center and Pointa
3. Create a rotated point (WorkPoint by off-seting the Center (polar) by distance dist at angle a plus the parameter Angle.
Unit checking in rotated region can be slightly painful. You have to create an invisible target dummy unit, set it's radius to the radius of the unit you're checking and see if that unit, placed at the position of WorkPoint, is in the region. You can use the Point version for unit checking, but it will only register positive if your unit's center is standing directly in the region.
More on that later.
Uses
You can use this function for many different things. You can:
Trace-lines (for TPS and FPS) that are as accurate in width as a bullet.
Make a rotating lava bridge (I don't know)
Anything!
So, thanks for reading, GLHF, and I've uploaded a test map with a super cool region I designed myself.
Ok i've just faced problems when decided to create rotated rectangle region and found this awesome stuff. However i assume if i want to get all units within this rotated region i will need to make a loop for each unit in map right...? And also figure out how to add unit's radius delta.
Rotated Region Collision
In the Starcraft 2 Editor, there are three standard types of regions: Circles, Rectangles, and Diamonds. These are very basic shapes and don't support rotations whatsoever. Here is how to make them work in that regard.
Overview
This function does not work by rotating the region. Instead, it rotates the checking point in relation to the pseudo-angle of an imaginary rotated region. The rotation is only applied to the checking point (in relation to the center of the region) and not to the region itself.This is much better on the CPU and takes a ton less math, is perfectly accurate, and uses the built in Point/Unit Is In Region (allowing for support of any regions built of as many of the standard shapes as you want). And, it's surprisingly simple.
On the left, the region is not actually rotated, only the point. On the right is the final product.
There will be two function when we are done that return booleans:
Now, let's get started...
The Code and Theory
Basically, the required parameters are very similar to the standard "Point Is In Region", except we add one more parameter to the function: Angle. The reference point of the rotation is the regions center.
Center is the center of the region. Point is the point we are testing to see if it's in the region. WorkPoint is the final test point we calculated after rotating.
So, the trick:
Unit Check
Unit checking in rotated region can be slightly painful. You have to create an invisible target dummy unit, set it's radius to the radius of the unit you're checking and see if that unit, placed at the position of WorkPoint, is in the region. You can use the Point version for unit checking, but it will only register positive if your unit's center is standing directly in the region.
More on that later.
Uses
You can use this function for many different things. You can:
So, thanks for reading, GLHF, and I've uploaded a test map with a super cool region I designed myself.
Potentially useful.
Contribute to the wiki (Wiki button at top of page) Considered easy altering of the unit textures?
https://www.sc2mapster.com/forums/resources/tutorials/179654-data-actor-events-message-texture-select-by-id
https://media.forgecdn.net/attachments/187/40/Screenshot2011-04-17_09_16_21.jpg
Agreed, this could be incredibly helpful.
Ok i've just faced problems when decided to create rotated rectangle region and found this awesome stuff. However i assume if i want to get all units within this rotated region i will need to make a loop for each unit in map right...? And also figure out how to add unit's radius delta.