Skip to content

Collision

The Collision class is used to describe collision information for objects.

You can obtain collision information using the Collision class in the following way:

First, create two cube objects in the scene, collider1 and collider2 (as shown in the image below). Add a BoxCollider component to each of them and set their positions to (0,0,0) and (0,2,0) respectively. Then, add a Rigidbody component to collider2 and enable the useGravity property. Finally, attach the script to the collider1 game object.

typeScript
OnCollisionEnter(collision):void{
        Debug.Log("Collision information when collision occurs",collision);
    }

成员变量

Collision.transform : Transform
(Read Only) The Transform component of the object that was collided with during a collision.
Collision.collider : Collider
(Read Only) The collider involved in the collision event.
Collision.rigidbody : Rigidbody
(Read Only) The Rigidbody component on the collider.
Collision.gameObject : GameObject
(Read Only) The game objects involved in the current collision event.
Collision.contactPoints : ContactPoint[]
(Read Only) The contact point(s) involved in the collision event.
Collision.contactCount : number
(Read Only) The number of contact points involved in the collision event.
Collision.impulse : Vector3
(Read Only) The total impulse applied to contact points on this collider.
Collision.relativeVelocity : Vector3
(Read Only) The relative linear velocity between two colliding objects.

成员方法

Collision.GetContactPoint ( index : number ) : ContactPoint
Get the contact point at the specified index when a collision occurs.