Set grid shape to convex polygon

main
copygirl 5 months ago
parent f180a21946
commit 4b4b1eac3d
  1. 15
      objects/Grid.cs

@ -116,17 +116,26 @@ public partial class Grid : Area3D
return _material;
}
BoxShape3D _shape;
ConvexPolygonShape3D _shape;
void UpdateCollisionShape()
{
if (Engine.IsEditorHint()) return;
if (_shape == null) {
_shape = new BoxShape3D();
_shape = new ConvexPolygonShape3D();
AddChild(new CollisionShape3D { Shape = _shape }, true);
}
_shape.Size = new(GridSize.X * StepSize, 0.001f, GridSize.Y * StepSize);
const float Offset = 0.001f;
var x = GridSize.X * StepSize / 2;
var y = GridSize.Y * StepSize / 2;
_shape.Points = [
new(-x, Offset, -y),
new( x, Offset, -y),
new( x, Offset, y),
new(-x, Offset, y),
];
}
ImmediateMesh _mesh;

Loading…
Cancel
Save