Example #1
0
        public void OnDetectLedge()
        {
            Vector3    halfExtents;
            Quaternion orientation;

            retroController.controllerCollider.ToWorldSpaceBox(out projectedCenter, out halfExtents, out orientation);
            projectedCenter += (transform.forward * ForwardOffset) + (Vector3.up * (UpOffset + halfExtents.y));

            RetroControllerProfile profile = retroController.Profile;

            // check if the area is free from overlapping
            int n_overlap = Physics.OverlapBoxNonAlloc(projectedCenter, halfExtents,
                                                       overlapingColliders, retroController.controllerCollider.transform.rotation, profile.SurfaceLayers, QueryTriggerInteraction.Ignore);

            if (n_overlap == 0)
            {
                RaycastHit hit;
                if (Physics.BoxCast(projectedCenter, halfExtents, Vector3.down, out hit, orientation,
                                    profile.GroundCheck, profile.SurfaceLayers, QueryTriggerInteraction.Ignore))
                {
                    float dot      = Vector3.Dot(hit.normal, Vector3.up);
                    float slopeDot = (profile.SlopeAngleLimit / 90f);
                    if (dot > slopeDot)
                    {
                        retroController.CheckPlatform(hit.collider);
                        OnLedge        = true;
                        GrabbingTarget = hit.collider;
                        localGrabPoint = hit.transform.InverseTransformPoint(hit.point);
                    }
                }
            }
        }
Example #2
0
        private void OnDrawGizmos()
        {
            if (retroController == null)
            {
                return;
            }

            if (Application.isPlaying)
            {
                Gizmos.color = Color.magenta;
                RetroControllerProfile profile = retroController.Profile;
                Gizmos.DrawCube(projectedCenter, profile.Size);

                if (GrabbingTarget)
                {
                    Gizmos.color = Color.magenta;
                    Gizmos.DrawSphere(GrabbingTarget.transform.TransformPoint(localEndPoint), 0.4f);
                    Gizmos.color = Color.blue;
                    Gizmos.DrawSphere(GrabbingTarget.transform.TransformPoint(localGrabPoint), 0.4f);
                }
            }
        }