Пример #1
0
        /// <summary>
        /// Set isGrounded
        /// sphere cast down just beyond the bottom of the capsule to see/
        /// if the capsule is colliding round the bottom
        /// </summary>
        private void GroundChecking(float magnitudeToCheck, ref bool groundValue, Vector3 dirRay)
        {
            if (entityJump && entityJump.IsJumpedAndNotReady())
            {
                return;
            }
            //isGrounded = false;
            //return;

            RaycastHit hitInfo;

            //Vector3 dirRaycast = playerGravity.GetMainAndOnlyGravity() * (radius + magnitudeToCheck);
            //Debug.DrawRay(rb.transform.position, dirRaycast * -1, Color.blue, 0.1f);
            if (Physics.SphereCast(rb.transform.position, sizeRadiusRayCast, dirRay, out hitInfo,
                                   magnitudeToCheck, entityController.layerMask, QueryTriggerInteraction.Ignore))
            {
                //si on est sur un mur Galaxy...
                if (entityController.IsMarioGalaxyPlatform(LayerMask.LayerToName(hitInfo.collider.gameObject.layer)))
                //&& !entityGravityAttractorSwitch.IsNormalIsOkWithCurrentGravity(hitInfo.normal, entityGravityAttractorSwitch.GetDirGAGravity()))
                {
                    //si on était en l'air, test la gravité par rapport à la vrai gravité !
                    if (isFlying && !baseGravityAttractorSwitch.IsNormalIsOkWithCurrentGravity(hitInfo.normal, -baseGravityAttractorSwitch.GravityDirection))
                    {
                        Debug.Log("here sphereAirMove tell us we are in a bad normal, (we were inAir before) continiue to fall");
                        groundValue = false;
                        return;
                    }
                    else if (!isFlying && !baseGravityAttractorSwitch.IsNormalIsOkWithCurrentGravity(hitInfo.normal, baseGravityAttractorSwitch.GetWantedGravityOnGround()))
                    {
                        Debug.Log("here sphereAirMove tell us we are in a bad normal, (we were onGround Before, first time fly ?) continiue to fall");
                        groundValue = false;
                        return;
                    }
                }

                if (SetCurrentPlatform(hitInfo.collider.transform))
                {
                    //Debug.Log("test de fastForward ?");
                }

                groundValue = true;

                if (calculateSurfaceNormal)
                {
                    dirSurfaceNormal = ExtVector3.GetSurfaceNormal(rb.transform.position,
                                                                   baseGravity.GetMainAndOnlyGravity() * -0.01f,
                                                                   groundCheckDistance,
                                                                   sizeRadiusRayCast,
                                                                   hitInfo.point,
                                                                   collRayCastMargin,
                                                                   entityController.layerMask);
                }
                else
                {
                    dirSurfaceNormal = hitInfo.normal;
                }


                bool previous = fastForward && fastForward.IsInFastForward() && !fastForward.SwithcingIsRunning();
                if (CanChangeNormal(hitInfo))
                {
                    dirNormal = hitInfo.normal;
                    pointHit  = hitInfo.point;

                    if (fastForward && previous && fastForward.IsInFastForward())
                    {
                        //Debug.LogWarning("mmm ici ???");
                        dirNormal = dirSurfaceNormal;
                    }

                    /*
                     * Vector3 tmpOrientedGravity = dirNormal;
                     * if (fastForward && fastForward.DoChangeOrientationManually(hitInfo, ref tmpOrientedGravity))
                     * {
                     *  Debug.LogWarning("ici fast forwaard");
                     *  dirNormal = tmpOrientedGravity.normalized;
                     * }
                     */
                }
            }
            else
            {
                groundValue = false;
                //dirNormal = baseGravity.GetMainAndOnlyGravity() * 1;
            }
        }
        private void ForwardWallCheck()
        {
            RaycastHit hitInfo;

            ResetContact();
            isAdvancedForward = isForwardAdvanceNormalOk = false;

            //do nothing if not moving
            if (!entityAction.IsMoving())
            {
                return;
            }
            //do nothing if input and forward player are not equal
            if (!entityController.IsLookingTowardTheInput(dotMarginImpact))
            {
                return;
            }

            AdvanceForwardCheck();

            if (Physics.SphereCast(rb.transform.position, sizeRadiusForward, entityController.GetFocusedForwardDirPlayer(), out hitInfo,
                                   distForward, entityController.layerMask, QueryTriggerInteraction.Ignore))
            {
                //if (!IsSphereGravityAndNormalNotOk(hitInfo))
                //    return;


                //ExtDrawGuizmos.DebugWireSphere(rb.transform.position + (entityController.GetFocusedForwardDirPlayer()) * (distForward), Color.yellow, sizeRadiusForward, 0.1f);
                //Debug.DrawRay(rb.transform.position, (entityController.GetFocusedForwardDirPlayer()) * (distForward), Color.yellow, 5f);
                //ExtDrawGuizmos.DebugWireSphere(hitInfo.point, Color.red, 0.1f, 0.1f);

                isForwardWall = true;

                Vector3 normalHit           = hitInfo.normal;
                Vector3 upPlayer            = entityGravity.GetMainAndOnlyGravity();
                Vector3 tmpDirSurfaceNormal = ExtVector3.GetSurfaceNormal(rb.transform.position,
                                                                          entityController.GetFocusedForwardDirPlayer(),
                                                                          distForward,
                                                                          sizeRadiusForward,
                                                                          hitInfo.point,
                                                                          collRayCastMargin,
                                                                          entityController.layerMask);
                if (tmpDirSurfaceNormal != Vector3.zero)
                {
                    dirSurfaceNormal = tmpDirSurfaceNormal;
                }

                entitySlide.CalculateStraffDirection(dirSurfaceNormal);    //calculate SLIDE

                float dotWrongSide = Vector3.Dot(upPlayer, normalHit);
                if (dotWrongSide < -dotMarginImpact)
                {
                    //Debug.Log("forward too inclined, dotImpact: " + dotWrongSide + "( max: " + dotMarginImpact + ")");
                    isForbiddenForward = true;
                    return;
                }

                //int isForbidden = ExtList.ContainSubStringInArray(walkForbiddenForwardUp, LayerMask.LayerToName(hitInfo.transform.gameObject.layer));
                if (!IsNormalOk(hitInfo))
                {
                    //here we are in front of a forbidden wall !!
                    isForbiddenForward = true;

                    entityBumpUp.HereBumpUp(hitInfo, dirSurfaceNormal);
                }
                else
                {
                    if (groundCheck.IsFlying() && !inAirForwardWall)
                    {
                        isForbiddenForward = true;
                    }
                    else
                    {
                        //HERE FORWARD, DO SWITCH !!
                        coolDownForward.StartCoolDown(timeBetween2TestForward);
                        //Debug.Log("forward");
                        groundCheck.SetForwardWall(hitInfo);

                        isForbiddenForward = false;
                    }
                }
            }
            else
            {
                ResetContact();
            }
        }