/// <summary> /// renvoi vrai si on peut se déplacer vers la où on veut en tense /// </summary> /// <returns></returns> public Vector3 GetTheGoodAngleWhenTenseInAirMove(Vector3 dirPlayer) { //si on est grounded, faire gaffe à pas bouger si on vise le mur ! Vector3 dirInversePlayer = -dirPlayer; //une fois que j'ai mon vecteur, prendre l'inverse Vector3 dirNormal = worldCollision.GetSumNormalSafe(); //prend la normal Debug.DrawRay(transform.position, dirPlayer * 2, Color.green, 1f); Debug.DrawRay(transform.position, dirInversePlayer * 2, Color.red, 1f); //float anglePlayer = QuaternionExt.GetAngleFromVector(dirPlayer); float angleInverse = QuaternionExt.GetAngleFromVector(dirInversePlayer); float angleNormal = QuaternionExt.GetAngleFromVector(dirNormal); float diffAngleNormalInverse; bool isCLose = QuaternionExt.IsAngleCloseToOtherByAmount(angleNormal, angleInverse, playerAirMove.DiffAngleWhenWeCantMoveThisWay, out diffAngleNormalInverse); //Debug.Log("Diff angleNormal/angleInverse: " + diffAngleNormalInverse); if (!isCLose) { return(dirPlayer); } //Debug.Break(); return(Vector3.zero); }
/// <summary> /// Ground, //0 Wall, //1 Ceilling //2 /// /// Ground, //0 /// GroundLeft, //1 /// GroundRight, //2 /// WallLeft, //3 /// WallRight, //4 /// CeilingLeft, //5 /// CeilingRight, //6 /// Ceilling, //7 /// /// <param name="normal">direction de la normal de collision</param> /// <returns>retourne un type de collision ( explicite)</returns> private int WhatKindOfNormalIsIt(Vector3 normal) { if (normal == Vector3.zero) { //Debug.Log("return -1, la normal fourni est 0"); return(-1); } float angleNormal = QuaternionExt.GetAngleFromVector(normal); //angle normal collision //si la normal de contact est proche de 0 ou 180, à 20° près, alors on est en mode wallJump... float diffAngle = 0; for (int i = 0; i < angleReference.Length; i++) { bool groundType = QuaternionExt.IsAngleCloseToOtherByAmount(angleNormal, angleReference[i], angleDifference, out diffAngle); if (groundType) { //Debug.Log(angleReferenceDisplay[i] + ", angleNormal: " + angleNormal + "(diff:" + diffAngle + ")"); return(i); } } //Debug.Log("return -1"); return(-1); }
/// <summary> /// ajout / enleve avec l'input du joueur up / down /// </summary> private void ModifyRopeUpDown() { if (!CanModifyUpDown()) { return; } Vector3 dirRope = Vector3.zero; if (!ropeHandler.IsTenseForAirMove) { //ici on reprend avec l'angle d'avant de la rope dirRope = holdDirRope; } else { dirRope = ropeHandler.GetVectorFromPlayer(playerController.IdPlayer); //dirRope = playerPenduleMove.GetDirRopeFromPivot(); holdDirRope = dirRope; timeWhenWeCanModifyRope.StartCoolDown(); } Vector3 dirRopeInverse = -dirRope; Vector3 dirInput = playerInput.GetDirInput(); float angleRope = QuaternionExt.GetAngleFromVector(dirRope); float angleRopeInverse = QuaternionExt.GetAngleFromVector(dirRopeInverse); float angleInput = QuaternionExt.GetAngleFromVector(dirInput); Debug.DrawRay(transform.position, dirRope, Color.green, 1f); Debug.DrawRay(transform.position, dirInput, Color.red, 1f); float diffAngleRopeNormal; if (QuaternionExt.IsAngleCloseToOtherByAmount(angleInput, angleRope, diffAngleForUpAndDown, out diffAngleRopeNormal)) { //Debug.Log("delete"); RemoveRopeParticle(); } else if (QuaternionExt.IsAngleCloseToOtherByAmount(angleInput, angleRopeInverse, diffAngleForUpAndDown, out diffAngleRopeNormal)) { //Debug.Log("add"); AddRopeParticle(); } }
/// <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> /// 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); } } } }
/// <summary> /// ici cherche le premier point de pivot, puis assigne la distance, et le nombre de particule player - point de pivot. /// </summary> public void GetPivotPoint(int indexPlayer, float angleDifferenceMarginForPivotPoint, float marginAngleConsideredAsEqual, out float distance, out int numberParticleFromPlayerToPivot, out Vector3 pointPivot, out bool onRope) { int startPoint = 4; //ici commence au Xeme point... float diffAdd = 0; //ici la somme des différence d'angles à chaque test int numberParticleTested = startPoint; //ici le nombre de particule testé onRope = false; Vector3 lastDir = Vector3.zero; //défini le vecteur directeur précédent Vector3 currentDir = Vector3.zero; //défini le vecteur à tester courrament dans la boucle if (indexPlayer == 0) { Vector3 posFirst = GetPosParticle(0); Vector3 posSecond = GetPosParticle(0 + startPoint); lastDir = posSecond - posFirst; for (int i = startPoint; i <= GetSizeConstrain() - 1; i++) { Vector3 posFirstTmp = posFirst; posFirst = GetPosParticle(i); posSecond = GetPosParticle(i + 1); currentDir = posSecond - posFirst; //Debug.Log("posActualPartivcleTested(current): " + posFirst); //Debug.Log("pos next: " + posSecond); //Debug.Log("current Direction: " + currentDir); if (currentDir == Vector3.zero) { //ici ok même angle, on continue //DebugExtension.DebugWireSphere(GetPosParticle(i), Color.blue, 1f, 1f); numberParticleTested++; //lastDir = currentDir; //Debug.Log("next"); continue; } //Debug.DrawRay(posFirstTmp, lastDir, Color.red, 1f); //Debug.DrawRay(posFirst, currentDir, Color.cyan, 1f); float anglePrevious = QuaternionExt.GetAngleFromVector(lastDir); float angleCurrent = QuaternionExt.GetAngleFromVector(currentDir); float diffAngleDir; QuaternionExt.IsAngleCloseToOtherByAmount(anglePrevious, angleCurrent, angleDifferenceMarginForPivotPoint, out diffAngleDir); if (diffAngleDir > marginAngleConsideredAsEqual) { diffAdd += diffAngleDir; } //Debug.Log("anglePrevious: " + anglePrevious + ", angleCurrent: " + angleCurrent); //Debug.Log("diffAdd: " + diffAdd + " (+" + diffAngleDir + ")"); if (diffAdd < angleDifferenceMarginForPivotPoint) { //ici ok même angle, on continue //DebugExtension.DebugWireSphere(GetPosParticle(i), Color.blue, 1f, 1f); numberParticleTested++; lastDir = currentDir; //Debug.Log("next"); } else { //ici on a changé d'angle ! (soit brutalement, soit avec le temps) //ici prendre... la différence entre le premier et ce dernier point testé pointPivot = GetPosParticle(i); distance = Vector3.Distance(playerManager.GetPosPlayer(indexPlayer), pointPivot); numberParticleFromPlayerToPivot = numberParticleTested; //Debug.Log("ici !"); onRope = true; DebugExtension.DebugWireSphere(GetPosParticle(i), Color.blue, 1f, 1f); //Debug.Break(); return; } } //Debug.Log("on prend le dernier"); //ici prendre... le dernier player. (et la distance par rapport au premier player) pointPivot = playerManager.GetPosPlayer(1); distance = Vector3.Distance(playerManager.GetPosPlayer(0), pointPivot); numberParticleFromPlayerToPivot = numberParticleTested; return; } else { Vector3 posFirst = GetPosParticle(GetSizeConstrain()); Vector3 posSecond = GetPosParticle(GetSizeConstrain() - startPoint); lastDir = posSecond - posFirst; for (int i = GetSizeConstrain() - startPoint; i >= 1; i--) { Vector3 posFirstTmp = posFirst; posFirst = GetPosParticle(i); posSecond = GetPosParticle(i - 1); currentDir = posSecond - posFirst; if (currentDir == Vector3.zero) { //ici ok même angle, on continue //DebugExtension.DebugWireSphere(GetPosParticle(i), Color.blue, 1f, 1f); numberParticleTested++; //lastDir = currentDir; //Debug.Log("next"); continue; } //Debug.DrawRay(posFirstTmp, lastDir, Color.red, 1f); //Debug.DrawRay(posFirst, currentDir, Color.cyan, 1f); float anglePrevious = QuaternionExt.GetAngleFromVector(lastDir); float angleCurrent = QuaternionExt.GetAngleFromVector(currentDir); float diffAngleDir; QuaternionExt.IsAngleCloseToOtherByAmount(anglePrevious, angleCurrent, angleDifferenceMarginForPivotPoint, out diffAngleDir); diffAdd += diffAngleDir; if (diffAdd < angleDifferenceMarginForPivotPoint) { //ici ok même angle, on continue //DebugExtension.DebugWireSphere(GetPosParticle(i), Color.red, 1f, 1f); numberParticleTested++; lastDir = currentDir; } else { //ici on a changé d'angle ! (soit brutalement, soit avec le temps) //ici prendre... la différence entre le dernier et ce dernier point testé pointPivot = GetPosParticle(i); distance = Vector3.Distance(playerManager.GetPosPlayer(indexPlayer), pointPivot); numberParticleFromPlayerToPivot = numberParticleTested; onRope = true; return; } } //ici prendre... le premier player. (et la distance par rapport au dernier player) pointPivot = playerManager.GetPosPlayer(0); distance = Vector3.Distance(playerManager.GetPosPlayer(1), pointPivot); numberParticleFromPlayerToPivot = numberParticleTested; return; } }