Exemple #1
0
    public bool DeactivateBallMode(BetterCharacterController characterController, out Vector3 velocity)
    {
        velocity = rb.velocity;
        Vector3 XZForward = new Vector3(rb.velocity.x, 0, rb.velocity.z);

        if (XZForward.magnitude < 0.1f)
        {
            XZForward = new Vector3(transform.forward.x, 0, transform.forward.z).normalized;
            if (XZForward.magnitude == 0)
            {
                XZForward = Vector3.forward;
            }
        }
        Vector3    ballPosition      = transform.TransformPoint(sphereCollider.center);
        Vector3    savedTransformPos = transform.position;
        Quaternion savedTransformRot = transform.rotation;

        transform.LookAt(transform.position + XZForward, Vector3.up);
        transform.position = ballPosition - sphereCollider.center + new Vector3(0, 0.001f, 0);
        if (!characterController.ResolveIntersection(characterController.capsuleRadius / 2))
        {
            transform.position = savedTransformPos;
            transform.rotation = savedTransformRot;
            return(false);
        }
        rb.isKinematic = true;
        characterController.enabled = true;
        return(true);
    }
Exemple #2
0
 private void ResolveCollisions(Collider collider)
 {
     Collider[] overlappingColliders = Physics.OverlapBox(collider.bounds.center, collider.bounds.extents, Quaternion.identity, charactersLayerMask);
     foreach (Collider c in overlappingColliders)
     {
         BetterCharacterController controller = c.GetComponent <BetterCharacterController>();
         if (controller)
         {
             controller.ResolveMovingObjIntersection(collider);
         }
     }
 }