/// <summary>
    /// retourne la direction quand on saute...
    /// </summary>
    /// <returns></returns>
    private Vector3 GetDirWhenJumpAndMoving()
    {
        Vector3 finalVelocityDir = Vector3.zero;

        //get la direction du joystick
        Vector3 dirInputPlayer = playerInput.GetDirInput();

        //get le dot product normal -> dir Arrow
        float dotDirPlayer = QuaternionExt.DotProduct(worldCollision.GetSumNormalSafe(), dirInputPlayer);

        //si positif, alors on n'a pas à faire de mirroir
        if (dotDirPlayer > margeHoriz)
        {
            //direction visé par le joueur
            Debug.Log("Direction de l'arrow !" + dotDirPlayer);
            finalVelocityDir = dirInputPlayer.normalized;
        }
        else if (dotDirPlayer < -margeHoriz)
        {
            //ici on vise dans le négatif, faire le mirroir du vector par rapport à...
            Debug.Log("ici mirroir de l'arrow !" + dotDirPlayer);

            //récupéré le vecteur de DROITE de la normal
            Vector3 rightVector = QuaternionExt.CrossProduct(worldCollision.GetSumNormalSafe(), Vector3.forward) * -1;
            //Debug.DrawRay(transform.position, rightVector.normalized, Color.blue, 1f);

            //faire le mirroir entre la normal et le vecteur de droite
            Vector3 mirror = QuaternionExt.ReflectionOverPlane(dirInputPlayer, rightVector * -1) * -1;
            //Debug.DrawRay(transform.position, mirror.normalized, Color.yellow, 1f);

            //direction inverse visé par le joueur
            finalVelocityDir = mirror.normalized;
        }
        else
        {
            Debug.Log("ici on est proche du 90°, faire la bisection !");
            //ici l'angle normal - direction est proche de 90°, ducoup on fait le milieu des 2 axe
            //ici faire la moyenne des 2 vecteur normal, et direction arrow
            finalVelocityDir = QuaternionExt.GetMiddleOf2Vector(worldCollision.GetSumNormalSafe(), dirInputPlayer);
        }
        return(finalVelocityDir);
    }
Beispiel #2
0
    /// <summary>
    /// ici est appelé a chaque fixedUpdate, on doit aller dans une direction !!
    /// </summary>
    private void ControlledAirJump()
    {
        //Vector3 dirRope = ropeHandler.GetVectorFromPlayer(playerController.IdPlayer);
        Vector3 dirRope = transform.position - savePivot;

        Vector3 dirLeft  = -QuaternionExt.CrossProduct(dirRope, Vector3.forward).normalized;
        Vector3 dirRight = QuaternionExt.CrossProduct(dirRope, Vector3.forward).normalized;
        Vector3 dirJump  = previousControllerJumpDir;

        float angleLeft  = QuaternionExt.GetAngleFromVector(dirLeft);
        float angleRight = QuaternionExt.GetAngleFromVector(dirRight);
        float angleJump  = QuaternionExt.GetAngleFromVector(dirJump);
        //calcul de direction

        float diffAngleLeftNormal;

        QuaternionExt.IsAngleCloseToOtherByAmount(angleLeft, angleJump, 179f, out diffAngleLeftNormal);
        float diffAngleRightNormal;

        QuaternionExt.IsAngleCloseToOtherByAmount(angleRight, angleJump, 179f, out diffAngleRightNormal);

        if (diffAngleLeftNormal < diffAngleRightNormal)
        {
            dirJump = dirLeft;
        }
        else
        {
            dirJump = dirRight;
        }
        previousControllerJumpDir = dirJump;


        Debug.DrawRay(transform.position, dirJump * currentJumpBoost * 10, Color.white, 1f);
        //a la fin, effectuer la force
        playerPenduleAirMove.ApplyAirMoveForce(dirJump, currentJumpBoost * playerGetFat.boostAirMoveWhenFat());

        //currentJumpBoost -= 0;
    }
    /// <summary>
    /// ici n'active pas si la distance des 2 joueurs est trop courte
    /// par rapport aux nombre de particule dans la chaine
    /// </summary>
    /// <returns></returns>
    private bool CheckDistanceAndNumberParticle()
    {
        //int numberParticle = ropeHandler.ParticleInRope;
        float distance = 0;
        int   numberParticleFromPlayerToPivot = 0;

        pointPivot = Vector3.zero;
        bool onRope = false;

        ropeHandler.GetPivotPoint(playerController.IdPlayer, angleDifferenceMarginForPivotPoint, marginAngleConsideredAsEqual, out distance, out numberParticleFromPlayerToPivot, out pointPivot, out onRope);

//DebugExtension.DebugWireSphere(pointPivot, Color.magenta, 1f, 2f);
//Debug.Log("distance: " + distance);
//Debug.Log("number particle: " + numberParticleFromPlayerToPivot);

        //Debug.Log("numberParticle: " + numberParticle + ", distance: " + distance);
        if (IsOnRightDist(numberParticleFromPlayerToPivot, distance))
        {
            //ici on est dans la bonne distance
            //Debug.Log("ici OK");
            if (onRope)
            {
                GameObject particle = ObjectsPooler.Instance.SpawnFromPool(GameData.PoolTag.ParticleRopeTense, pointPivot, Quaternion.identity, ObjectsPooler.Instance.transform);
                particle.transform.rotation = QuaternionExt.LookAtDir(QuaternionExt.CrossProduct(pointPivot - transform.position, Vector3.forward) * -1);
            }

            //MessageBox.Show("Something happened. Attach the debugger, add a breakpoint to the line after this one, then press OK.");
            //"does nothing".ToString(); // place breakpoint here
            //Debug.Break();
            return(true);
        }
        //Debug.Log("ici PAS OK");
        //MessageBox.Show("Something happened. Attach the debugger, add a breakpoint to the line after this one, then press OK.");
        //"does nothing".ToString(); // place breakpoint here
        //Debug.Break();
        //ici dans la mauvaise distance
        return(false);
    }
Beispiel #4
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);
                }
            }
        }
    }