Deducing Altitude - sh4rkman/SquadCalc GitHub Wiki
⬅️
Previous: Deducing Distance & Bearing
•
Next: Deducing Elevation
➡️
Now that we found the distance and the angle between weapon and target, we can already calculate the elevation angle to hit the target. But what if the target is up a 30 meters hill ? The distance we have is stricly on 2 dimensions, we have no information about the third dimension : height (or altitude, call it what you want).
SquadCalc uses Squad SDK's heightmap to figure out the height of the weapon and target positions on a map. The SquadCalc heightmap is a special version colored with a blue-to-red gradient, where the colors show different heights.
See Adding a new map for more info on how to extract and color heightmaps.
default SDK heightmap vs squadcalc colored one
- Load the Heightmap:
We start by loading the heightmap image into a hidden html canvas. This image uses colors to represent heights – blue for lower areas and red for higher areas.
- Read Pixel Values:
We pick the pixel at the weapon and target positions on the heightmap and read the RGB (Red, Green, Blue) values of those pixels.
- Calculate Height:
The height at each point is determined from the RGB values: Red Channel: Indicates height. Higher red values mean greater heights. Blue Channel: Indicates depth. Higher blue values mean lower areas.
Moreover, each map has a z-scaling value set in squad's SDK, from there we can deduce the height of each pixel of the heightmap :
/**
* Calculate height for a given color and map z-scaling
* @param{RGB} Color
*/
getHeight(color){
return (255 + color[0] - color[2]) * mapZScaling;
}
PositionA = RGB(200, 0, 55);
PositionB = RGB(70, 0, 2);
getHeight(PositionA); // = 36m
getHeight(PositionB); // = 11m
HeightDiff = getHeight(PositionB) - getHeight(PositionA); // = 25m !
The Squad (and probably every Unreal Engine games) heightmaps are only a reflection of the terrain. Buildings, bridges and other game assets are not part of it. That means that if you build you weapon on the top of a building (you shouldn't) SquadCalc have no idea that your weapon have some altitude and will think you are on the ground.
If you still want to place your weapon on a bridge/building (again, you shouldn't) you can tell squadcalc about it and manually add height to it, just click any weapon :
⬅️
Previous: Deducing Distance & Bearing
•
Next: Deducing Elevation
➡️