From 4b4b1eac3d80f340ecf4f4f8852fd21497e7dd76 Mon Sep 17 00:00:00 2001 From: copygirl Date: Mon, 1 Jan 2024 18:52:14 +0100 Subject: [PATCH] Set grid shape to convex polygon --- objects/Grid.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/objects/Grid.cs b/objects/Grid.cs index a450e19..25e1b3c 100644 --- a/objects/Grid.cs +++ b/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;