Skip to content

Commit 0cc2e76

Browse files
committed
Fix vehicle turret rendering
1 parent 771b21b commit 0cc2e76

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/TSMapEditor/Rendering/ObjectRenderers/UnitRenderer.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ protected override CommonDrawParams GetDrawParams(Unit gameObject)
2626
};
2727
}
2828

29+
protected override float GetDepthFromPosition(Unit gameObject, int bottomDrawPoint)
30+
{
31+
// Because vehicles can include turrets, the default implementation
32+
// is not suitable. For example, bodies can be rendered southward of turrets
33+
// facing north, leading the bodies to have higher depth and overlapping turrets.
34+
//
35+
// Instead, we calculate a positional depth value using the vehicle's cell.
36+
// This depth value is identical for the base vehicle sprite and turret,
37+
// making it easy to draw the turret either above or below the vehicle
38+
// by applying DepthEpsilon.
39+
var cell = Map.GetTile(gameObject.Position);
40+
41+
int height = 0;
42+
if (cell != null)
43+
{
44+
height = cell.Level;
45+
}
46+
47+
return ((CellMath.CellTopLeftPointFromCellCoords(cell.CoordsToPoint(), Map).Y + Constants.CellSizeY) / (float)Map.HeightInPixelsWithCellHeight) * Constants.DownwardsDepthRenderSpace +
48+
(height * Constants.DepthRenderStep);
49+
}
50+
2951
protected override float GetDepthAddition(Unit gameObject)
3052
{
3153
return Constants.DepthEpsilon * ObjectDepthAdjustments.Vehicle;

0 commit comments

Comments
 (0)