using UnityEngine; namespace Lightbug.Utilities { /// /// Struct that contains the information of the contact, gathered from the collision message ("enter" and "stay"). /// public readonly struct Contact { /// /// Flag that indicates the enter state (OnContactEnter) of the contact. /// public readonly bool firstContact; /// /// The contact point. /// public readonly Vector3 point; /// /// The contact normal. /// public readonly Vector3 normal; /// /// The 2D collider component associated with the collided object. /// public readonly Collider2D collider2D; /// /// The 3D collider component associated with the collided object. /// public readonly Collider collider3D; /// /// Flag that indicates if the collided object is a rigidbody or not. /// public readonly bool isRigidbody; /// /// Flag that indicates if the collided object is a kinematic rigidbody or not. /// public readonly bool isKinematicRigidbody; /// /// The relative velocity of the rigidbody associated. /// public readonly Vector3 relativeVelocity; /// /// The contact point velocity. This value corresponds to the ground rigidbody velocity. /// public readonly Vector3 pointVelocity; /// /// The gameObject representing the collided object. /// public readonly GameObject gameObject; public Contact(bool firstContact, ContactPoint2D contact, Collision2D collision) : this() { this.firstContact = firstContact; this.collider2D = contact.collider; this.point = contact.point; this.normal = contact.normal; this.gameObject = this.collider2D.gameObject; var contactRigidbody = this.collider2D.attachedRigidbody; this.relativeVelocity = collision.relativeVelocity; if (this.isRigidbody = contactRigidbody != null) { this.isKinematicRigidbody = contactRigidbody.isKinematic; this.pointVelocity = contactRigidbody.GetPointVelocity(this.point); } } public Contact(bool firstContact, ContactPoint contact, Collision collision) : this() { this.firstContact = firstContact; this.collider3D = contact.otherCollider; this.point = contact.point; this.normal = contact.normal; this.gameObject = this.collider3D.gameObject; var contactRigidbody = this.collider3D.attachedRigidbody; this.relativeVelocity = collision.relativeVelocity; if (this.isRigidbody = contactRigidbody != null) { this.isKinematicRigidbody = contactRigidbody.isKinematic; this.pointVelocity = contactRigidbody.GetPointVelocity(this.point); } } public Contact(Vector3 point, Vector3 normal, Vector3 pointVelocity, Vector3 relativeVelocity) : this() { this.point = point; this.normal = normal; this.pointVelocity = pointVelocity; this.relativeVelocity = relativeVelocity; } } }