/// <summary>
    /// ici effectue les mouvements en l'air (selon la corde tendu ?)
    /// </summary>
    private void AirMove()
    {
        Vector3 dirRope      = ropeHandler.GetVectorFromPlayer(playerController.IdPlayer);
        Vector3 dirReference = playerInput.GetDirInput();

        dirPlayerAirMove = QuaternionExt.GetTheGoodRightAngleClosest(dirRope, dirReference, 10f);


        if (dirPlayerAirMove == Vector3.zero)
        {
            return;
        }

        if (!ForceGroundedInCoolDown())
        {
            return;
        }

        if (WeJustInversePendule())
        {
            //Debug.LogWarning("ici on a inversé !");
            SetInverse();
        }

        //ici on est bon !
        DoNewPenduleForce();
    }
    /// <summary>
    /// retourne l'angle correct
    /// </summary>
    /// <returns></returns>
    public Vector3 GetTheGoodAngleWhenRopeTense()
    {
        Vector3 dirRope = ropeHandler.GetVectorFromPlayer(playerController.IdPlayer);
        //Vector3 dirRope = playerPenduleMove.GetDirRopeFromPivot();

        Vector3 dirReference = worldCollision.GetSumNormalSafe();

        return(QuaternionExt.GetTheGoodRightAngleClosest(dirRope, dirReference, 10f));
    }
Exemple #3
0
    /// <summary>
    /// déplace horizontalement le player
    /// </summary>
    private void MoveHorizOnGround(Vector3 velocityChange)
    {
        if (playerPenduleMove.IsAirTenseOrInCoolDown())
        {
            return;
        }

        Vector3 targetVelocity = velocityChange;

        //si on est en collision avec wall, ou ceilling, gérer ça à part
        if (!CheckCollisionType(velocityChange))
        {
            return;
        }

        //si il n'y a pas d'input, gérer la décélération ??
        if (velocityChange.x == 0)
        {
            DoSlowDownWhenNoInput();
            //animController.NotMoving();
            return;
        }
        //animController.IsMoving(playerInput.Horiz);

        previousInput = velocityChange.x;

        //TODO: rotate, ou remplacer velocityChange par le right/left de la normal de collision...
        //TODO;
        Vector3 dirNormal    = worldCollision.GetSumNormalSafe();
        Vector3 dirReference = velocityChange;

        if (dirNormal != Vector3.zero && dirReference != Vector3.zero)
        {
            Vector3 dir = QuaternionExt.GetTheGoodRightAngleClosest(dirNormal, dirReference, 10f);

            Vector3 direction = dir.normalized;
            float   speed     = velocityChange.magnitude;

            velocityChange = direction * speed;


            Vector3         normalRight = QuaternionExt.CrossProduct(velocityChange, Vector3.forward);
            CollisionSimple rightNormal = worldCollision.WhatKindOfNormalItIs(normalRight);

            Vector3         normalLeft = -QuaternionExt.CrossProduct(velocityChange, Vector3.forward);
            CollisionSimple leftNormal = worldCollision.WhatKindOfNormalItIs(normalLeft);

            /*Vector3 newDir = (rightNormal == CollisionSimple.Ground) ? normalRight : normalLeft;*/

            if (rightNormal == CollisionSimple.Ground || leftNormal == CollisionSimple.Ground)
            {
                if (worldCollision.IsOnCoinGround())
                {
                    //ChooseIfAccelerateOrVelocityChange(velocityChange, ratioForceInCoin);
                    CoinCase(velocityChange);
                }
                else
                {
                    float angle = QuaternionExt.GetAngleFromVector(direction);
                    //Debug.Log("angleDirection: " + angle);

                    if (QuaternionExt.IsAngleCloseToOtherByAmount(90, angle, angleNotAcceptedForOrientedMoveFrom90))
                    {
                        //Debug.Log("ici pas de force orienté par la normal");
                        //Debug.DrawRay(transform.position, dirReference, Color.green, 1f);
                        ChooseIfAccelerateOrVelocityChange(dirReference, ratioForceInBadAngle);
                        return;
                    }

                    if (worldCollision.GetSimpleCollisionSafe() == CollisionSimple.Wall)
                    {
                        ChooseIfAccelerateOrVelocityChange(velocityChange, ratioOnWall);
                    }
                    else
                    {
                        ChooseIfAccelerateOrVelocityChange(velocityChange, 1);
                    }


                    //rb.AddForce(velocityChange, ForceMode.VelocityChange);
                    //Debug.DrawRay(transform.position, velocityChange, Color.green, 1f);
                }
            }
        }
    }