Collision Description Class Collision
Collision information is passed to Collider. Oncollisionenter, Collider. Oncollisionstay and Collider.oncollisionexit events. See also: ContactPoint.
Variable
var collider:collider//Description: Collision-to-collider (read-only). To get the details of all colliding collider, you need to iterate over the contact point (Contacts attribute).
var contacts:contactpoint []//Description: The contact point is generated by the physical engine. Each contact contains a touch point, a normal and two colliding collider (refer to ContactPoint). Within Oncollisionstay or oncollisionenter, you can ensure that contacts has at least one element.
function Oncollisionstay (collision:collision) {
for (Var contact:contactpoint in collision. Contacts)//check to see if the collider has a rigid body
{
Print (contact.thiscollider. Name + ' hit ' + contact. Othercollider. Name); Check to see if the collider has a rigid body
Debug.drawray (contact point, contact. Normal, Color. White); Visualize Contact points
}
}
var explosionprefab:transform;
function Oncollisionenter (collision:collision)//A grenade that initializes an explode preset when hitting a surface, then destroys it
{
var contact = collision. Contact [0];
var rot = quaternion. Fromtorotation (vector3.up, contact. Normal);
var pos = contact. Point;
Instantiate (Explosionprefab, POS, rot);//Rotate This object so that the y-axis faces along the surface normal direction
Destory (gameobject);//Destroy This projectile
}
var gameobject:gameobject//Description:/Gameobject/Is the object that is colliding with it (read only)
var Relativevelocity:vector3//Description: Relative linear speed of two colliding objects (read only).
function Oncllisionenter (collision:collision)
{
if (collision. relativevelocity. Magnitude > 2)//play sound when touching an object at a larger speed
Audio. Play ();
}
var rigibody:rigidbody//Description: Collision to the Rigidbody (read only), if the object encountered is a collider without additional rigid body, return null
function Oncollisionstay (collision:collision) {
if (collision. Rigidbody)//check to see if the collider has a rigid body, then make the force
{
Collision. Rigidbody. Addforce (Vector3. Up * 15); Let all the rigid bodies that come to me fly up
}
}
var transform:transform//Description: The transform (read-only) of the object that is colliding. If a collider with Rigidbody is encountered, the transform will be the transformation of all additional rigid bodies. If a collider without a rigid body is encountered, the transform will be the transform of all additional collider.
Collision Contact Point Structure contactpoint
ContactPoint the contact point where the collision occurred. The contact points are stored in the collision structure, see collision, collision. Oncollisionenter, collision. Oncollisionstay, collision. Oncollisionexit.
Variable
var Normal:vector3//Description: The normal of the contact point
var othercollider:collider//Description: Another collider in collision
var Point:vector3//Description: Contact point
var thiscollider:collider? Description: The first collider in a collision
Controllercolliderhit class
Controllercolliderhit was Charactercontroller. Oncontrollercolliderhit is used to give detailed information about collisions and how to handle them.
Variable
var collider:collider//Description: The collider hit by the controller.
var Controller:charactercontroller//Description: The controller that encountered the collider.
var gameobject:gameobject//Description: The game object that is encountered by the controller.
var Movedirection:vector3//Description: From the center of the capsule to the approximate direction of the contact point. This can be used to find a reasonable direction to apply the force to the contact of the rigid body.
var movelength:float//Description: How far the character has traveled when it encounters this collider. Note that this may be different from the one you passed to Charactercontroller. Move of. Because all the moves are constrained by the collider.
var Normal:vector3//Description: The normal of a collision surface in world space.
var Point:vector3//Description: Collision point in world space.
var rigidbody:rigidbody//Description: Rigid body encountered by the controller. Null if there is no contact to a rigid body but a static collider.
var transform:transform///Description: Transformation encountered by the Controller
Collision Description Class Collision