/// <summary> /// ici effectue la force au sol /// </summary> /// <param name="dirForce"></param> public void ChooseIfAccelerateOrVelocityChange(Vector3 dirForce, float ratio) { //Debug.Log("la ?"); MoveOnWallWhenAirMove(dirForce.normalized * Mathf.Abs(previousInput), ratio); return; Vector3 rigidbodyVelocity = rb.velocity; float dotResult = QuaternionExt.DotProduct(Vector3.right, rigidbodyVelocity); if ((QuaternionExt.DotProduct(Vector3.right, rigidbodyVelocity) >= 0 && playerInput.Horiz > 0) || (QuaternionExt.DotProduct(Vector3.right, rigidbodyVelocity) <= 0 && playerInput.Horiz < 0)) { //dans le sens MoveOnWallWhenAirMove(dirForce.normalized * Mathf.Abs(previousInput), ratio); } else { //inverse Vector3 addForce = dirForce.normalized * speedAcceleration * ratio * Mathf.Abs(previousInput) * Time.fixedDeltaTime; rb.AccelerateTo(addForce, maxSpeedConstante, ForceMode.Acceleration); } }
/// <summary> /// ici renvoi vrai si le sens du mouvement va vers le haut /// </summary> /// <returns></returns> private bool IsVelocityIsInGoodSide(PosQuadran posInSpace) { float dirRigidbody = 0; switch (posInSpace) { case PosQuadran.upLeft: dirRigidbody = QuaternionExt.DotProduct(-Vector3.right, rb.velocity); if (dirRigidbody > 0) { return(true); } else { return(false); } case PosQuadran.upRight: dirRigidbody = QuaternionExt.DotProduct(Vector3.right, rb.velocity); if (dirRigidbody > 0) { return(true); } else { return(false); } case PosQuadran.downLeft: dirRigidbody = QuaternionExt.DotProduct(Vector3.right, rb.velocity); if (dirRigidbody > 0) { return(true); } else { return(false); } case PosQuadran.downRight: dirRigidbody = QuaternionExt.DotProduct(-Vector3.right, rb.velocity); if (dirRigidbody > 0) { return(true); } else { return(false); } case PosQuadran.ambigous: default: return(false); } }
/// <summary> /// est-ce que l'input est dans le sens du mouvement ? /// </summary> /// <returns></returns> private bool IsGoodInputToVelocy() { float dirinput = QuaternionExt.DotProduct(playerInput.GetDirInput(), rb.velocity); if (dirinput > 0) { return(true); } else { return(false); } }
/// <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); }
/// <summary> /// déplace horizontalement le player /// </summary> private void MoveAir() { if (playerPenduleMove.IsAirTenseOrInCoolDown()) { return; } //animController.IsMoving(playerInput.Horiz); Vector3 addForce = new Vector3(playerInput.Horiz, 0, 0); Vector3 rigidbodyVelocity = rb.velocity; float dotResult = QuaternionExt.DotProduct(Vector3.right, rigidbodyVelocity); if ((QuaternionExt.DotProduct(Vector3.right, rigidbodyVelocity) >= 0 && playerInput.Horiz > 0) || (QuaternionExt.DotProduct(Vector3.right, rigidbodyVelocity) <= 0 && playerInput.Horiz < 0)) { if (rigidbodyVelocity.sqrMagnitude < maxSpeedRigidbodyForNormalAirMove) { //Debug.Log("dans le sens"); rb.AddForce(addForce * playerMove.speedAcceleration * ratioAirMove * Time.fixedDeltaTime, ForceMode.Acceleration); } } else { //Debug.Log("à l'inverse"); rb.AddForce(addForce * playerMove.speedAcceleration * ratioAirMoveInverse * Time.fixedDeltaTime, ForceMode.Acceleration); } /*//ratioAirMoveInverse * if (accel.sqrMagnitude > maxAccel * maxAccel) * { * * } * rb.AddForce(addForce * playerMove.speedAcceleration * ratioAirMove * Time.fixedDeltaTime, ForceMode.Acceleration); * //rb.AccelerateTo(addForce, maxSpeedConstante, ForceMode.Acceleration); */ return; }