Skip to content

ControllerColliderHit

The ControllerColliderHit class is used to describe collision information between a character controller and a collider.

You can obtain a ControllerColliderHit object in the following way:

First, create a cube collider and a capsule character controller in the scene (as shown in the image below). Set their positions to (0,0,0) and (0,-2,0) respectively. Add a BoxCollider component to the cube and a CharacterController component to the capsule. Attach the script to the capsule.

typeScript
OnStart(): void {
        
        let character = this.gameObject.GetComponent<CharacterController>(CharacterController);
        // Move the character controller up by one unit
        character.Move(new Vector3(0,1,0));

    }

    OnControllerColliderHit(controllerColliderHit):void{

        Debug.Log("Collision information when the character controller collides with a collider", controllerColliderHit);
        
    }

成员变量

ControllerColliderHit.collider : Collider
(Read Only) The collider of the object that was collided with.
ControllerColliderHit.controller : CharacterController
(Read Only) The character controller involved in the collision.
ControllerColliderHit.transform : Transform
(Read Only) The Transform component of the object collided with by the controller.
ControllerColliderHit.point : Vector3
(Read Only) The collision point of the character collider in world space.
ControllerColliderHit.gameObject : GameObject
(Read Only) The game object that was hit during a collision.
ControllerColliderHit.normal : Vector3
(Read Only) The normal of the surface the collider is colliding with in world space.
ControllerColliderHit.moveLength : number
(Read Only) The distance the character moved during the collision.
ControllerColliderHit.moveDirection : Vector3
(Read Only) The direction in which the character controller moves when a collision occurs.