// Handles the players interaction with objects private void RayCasting() { // Automatically picks up items foreach (Area2D CollidedArea in GetNode <Area2D>("ItemPickUpRange").GetOverlappingAreas()) { if (!(CollidedArea is ItemEntity it)) { continue; } it.PlayerColliding = true; it.PlayerBody = this; } // Interacts with interactable areas foreach (Area2D RayCast in GetTree().GetNodesInGroup("PlayerRays")) { var collided = false; // Checks if the area has and to breaks the loop if (RayCast.GetOverlappingAreas().Count <= 0) { continue; // Checks if the area has collided } var collidedTile = RayCast.GetOverlappingAreas()[0]; // Fetches the collided tile // Checks the tiles type switch (collidedTile) { // Handles interactable tiles case InteractableTile T: T.OutLine.Visible = true; T.PlayerColliding = true; T.PlayerBody = this; CollidingInteractable = T; collided = true; break; // Handles NPC's case NPC T: T.PlayerColliding = true; T.PlayerBody = this; collided = true; break; // Handles placed items case PlacedItem T: T.PlayerColliding = true; T.PlayerBody = this; CollidingInteractable = T; collided = true; break; } if (collided) { break; // Breaks the loop if collided } CollidingInteractable = null; // Clears the interactable tile if the area hasn't collided with a tile } }