From f180a219465c771304a4c99d23dcf3ece3070995 Mon Sep 17 00:00:00 2001 From: copygirl Date: Mon, 1 Jan 2024 18:51:21 +0100 Subject: [PATCH] Can only place item on grid top side --- player/PickupController.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/player/PickupController.cs b/player/PickupController.cs index 6e7670c..11ef40f 100644 --- a/player/PickupController.cs +++ b/player/PickupController.cs @@ -87,8 +87,16 @@ public partial class PickupController : Node3D if (!_player.IsLocal) return; EnsureCurrentItemValid(); + static bool CanPlaceAgainst(Grid grid, Vector3 normal) + { + normal = grid.GlobalBasis.Inverse() * normal; + return normal.IsEqualApprox(Vector3.Up); + } + if (HasItemsHeld) { if ((RayToMouseCursor() is RayResult ray) && (ray.Collider is Grid grid) + // Make sure this is placed against the top of the grid. + && CanPlaceAgainst(grid, ray.Normal) // Ensure item is not being added to itself or nested items. && !((grid.GetParent() == CurrentItem) || grid.ContainsItem(CurrentItem))) { var transform = CurrentItem.GlobalTransform with { Origin = ray.Position };