Separate interable layer into pickup and place

main
copygirl 11 months ago
parent 4b4b1eac3d
commit 60e6b8c564
  1. 2
      objects/Item.cs
  2. 2
      objects/grid.tscn
  3. 11
      player/PickupController.cs
  4. 3
      project.godot
  5. 19
      scripts/globals/PhysicsLayer.cs

@ -19,7 +19,7 @@ public partial class Item : RigidBody3D
}
// Set the collision properties here so we don't have to specify them in each item scene separately.
CollisionLayer = (uint)(PhysicsLayer.Item | PhysicsLayer.Interactable);
CollisionLayer = (uint)(PhysicsLayer.Item | PhysicsLayer.Pickup);
CollisionMask = (uint)(PhysicsLayer.Static | PhysicsLayer.Dynamic | PhysicsLayer.Player | PhysicsLayer.Item);
Freeze = FindParent("Grid") != null;

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://objects/Grid.cs" id="1_7yhbt"]
[node name="Grid" type="Area3D"]
collision_layer = 256
collision_layer = 512
collision_mask = 0
monitoring = false
script = ExtResource("1_7yhbt")

@ -94,7 +94,10 @@ public partial class PickupController : Node3D
}
if (HasItemsHeld) {
if ((RayToMouseCursor() is RayResult ray) && (ray.Collider is Grid grid)
// This ray will be blocked by static and dynamic objects.
const PhysicsLayer Mask = PhysicsLayer.Place | PhysicsLayer.Static | PhysicsLayer.Dynamic;
if ((RayToMouseCursor(Mask) 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.
@ -114,7 +117,7 @@ public partial class PickupController : Node3D
_grid = null;
}
} else {
var interactable = RayToMouseCursor()?.Collider;
var interactable = RayToMouseCursor(PhysicsLayer.Pickup)?.Collider;
// Remove the outline from the previously looked-at item.
if (CurrentItem != null) SetMeshLayerOutline(CurrentItem.Model, OutlineMode.Disable);
@ -138,7 +141,7 @@ public partial class PickupController : Node3D
}
}
RayResult RayToMouseCursor()
RayResult RayToMouseCursor(PhysicsLayer collisionMask)
{
var camera = _player.Camera.Camera;
var mouse = GetViewport().GetMousePosition();
@ -146,7 +149,7 @@ public partial class PickupController : Node3D
var to = from + camera.ProjectRayNormal(mouse) * PickupDistance;
var query = PhysicsRayQueryParameters3D.Create(from, to);
query.CollisionMask = (uint)PhysicsLayer.Interactable;
query.CollisionMask = (uint)collisionMask;
query.CollideWithAreas = true;
// Exclude the `CurrentItem` from collision checking if it's being held.
query.Exclude = HasItemsHeld ? [ CurrentItem.GetRid() ] : [];

@ -87,7 +87,8 @@ interact_place={
3d_physics/layer_2="Dynamic"
3d_physics/layer_3="Player"
3d_physics/layer_4="Item"
3d_physics/layer_9="Interactable"
3d_physics/layer_9="Pickup"
3d_physics/layer_10="Place"
[rendering]

@ -1,8 +1,17 @@
[Flags]
public enum PhysicsLayer : uint {
Static = 1 << 0,
Dynamic = 1 << 1,
Player = 1 << 2,
Item = 1 << 3,
Interactable = 1 << 8,
/// <summary> Objects that are part of the scene, and never move. </summary>
Static = 1 << 0,
/// <summary> Objects the player collides with, but may move. </summary>
Dynamic = 1 << 1,
/// <summary> The player. </summary>
Player = 1 << 2,
/// <summary> Small objects the player doesn't collide with, but collide with the player. </summary>
Item = 1 << 3,
/// <summary> Objects that may be picked up. </summary>
Pickup = 1 << 8,
/// <summary> Objects that other objects may be placed against. </summary>
Place = 1 << 9,
}

Loading…
Cancel
Save