// Copyright (C) 2023 Nicholas Maltbie // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and // associated documentation files (the "Software"), to deal in the Software without restriction, // including without limitation the rights to use, copy, modify, merge, publish, distribute, // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System.Collections.Generic; using UnityEngine; namespace nickmaltbie.OpenKCC.Utils { /// /// Abstraction to check for collisions and compute when this object would hit other objects. /// public interface IColliderCast : IRaycastHelper { /// /// Gets the bottom of the bounds of the collider. /// /// Position of the object when it is being checked. /// Rotation of the objecting when it is being checked. /// Bottom of the bounds of the collider. Vector3 GetBottom(Vector3 position, Quaternion rotation); /// /// Gets the list of objects overlapping with this object. /// /// Position of the object when it is being checked. /// Rotation of the objecting when it is being checked. /// Layer mask for checking which objects to collide with. /// Configuration for QueryTriggerInteraction when solving for collisions. /// Buffer around player when computing overlapping objects. /// The list of overlapping objects with this object. IEnumerable GetOverlapping(Vector3 position, Quaternion rotation, int layerMask = RaycastHelperConstants.DefaultLayerMask, QueryTriggerInteraction queryTriggerInteraction = RaycastHelperConstants.DefaultQueryTriggerInteraction, float skinWidth = 0.0f); /// /// Cast self and get the objects hit that exclude this object. /// /// Direction to cast self collider. /// Distance to cast self collider. /// Position of the object when it is being raycast. /// Rotation of the objecting when it is being raycast. /// Layer mask for checking which objects to collide with. /// Configuration for QueryTriggerInteraction when solving for collisions. /// Buffer around player when computing collisions. /// List of objects this hits when it is being raycast IEnumerable GetHits(Vector3 position, Quaternion rotation, Vector3 direction, float distance, int layerMask = RaycastHelperConstants.DefaultLayerMask, QueryTriggerInteraction queryTriggerInteraction = RaycastHelperConstants.DefaultQueryTriggerInteraction, float skinWidth = 0.01f); /// /// Cast self in a given direction and get the first object hit. /// /// Position of the object when it is being raycast. /// Rotation of the objecting when it is being raycast. /// Direction of the raycast. /// Maximum distance of raycast. /// First object hit and related information, will have a distance of Infinity if none /// is found. /// Layer mask for checking which objects to collide with. /// Configuration for QueryTriggerInteraction when solving for collisions. /// Buffer around player when casting object. /// True if an object is hit within distance, false otherwise. bool CastSelf(Vector3 position, Quaternion rotation, Vector3 direction, float distance, out IRaycastHit hit, int layerMask = RaycastHelperConstants.DefaultLayerMask, QueryTriggerInteraction queryTriggerInteraction = RaycastHelperConstants.DefaultQueryTriggerInteraction, float skinWidth = 0.01f); /// /// Get the vector to push this object out of overlapping objects with a max distance. /// /// Position of the object when it is being raycast. /// Rotation of the objecting when it is being raycast. /// Maximum distance the player can be pushed /// Layer mask for checking which objects to collide with. /// Configuration for QueryTriggerInteraction when solving for collisions. /// Buffer around player when computing overlapping objects. /// Direction to push the object, distance player was pushed. Vector3 PushOutOverlapping(Vector3 position, Quaternion rotation, float maxDistance, int layerMask = RaycastHelperConstants.DefaultLayerMask, QueryTriggerInteraction queryTriggerInteraction = RaycastHelperConstants.DefaultQueryTriggerInteraction, float skinWidth = 0.0f); } }