コード例 #1
0
        //Detect if character is on the floor
        private void DetectGrounded()
        {
            float   hradius = GetColliderHeightRadius();
            float   radius  = GetColliderRadius();
            Vector3 center  = GetColliderCenter();

            float gdist; Vector3 gnormal;

            is_grounded   = PhysicsTool.DetectGround(transform, center, hradius, radius, ground_layer, out gdist, out gnormal);
            ground_normal = gnormal;

            float slope_angle = Vector3.Angle(ground_normal, Vector3.up);

            is_grounded = is_grounded && slope_angle <= slope_angle_max;
        }
コード例 #2
0
        //Check if touching the ground
        private void DetectGrounded()
        {
            float radius        = (bounds_extent.x + bounds_extent.z) * 0.5f;
            float center_offset = bounds_extent.y;
            float hradius       = center_offset + ground_detect_dist;

            Vector3 center = transform.position + bounds_center_offset;

            center.y = transform.position.y + center_offset;

            float gdist; Vector3 gnormal;

            is_grounded   = PhysicsTool.DetectGround(transform, center, hradius, radius, ground_layer, out gdist, out gnormal);
            ground_normal = gnormal;
            grounded_dist = gdist;

            float slope_angle = Vector3.Angle(ground_normal, Vector3.up);

            is_grounded = is_grounded && slope_angle <= slope_angle_max;
        }