protected override void ComputeVelocity() { immunityTimeLeft -= Time.deltaTime; timeForNextDash -= Time.deltaTime; timeForNextInvisiblity -= Time.deltaTime; if (timeForNextDash <= 0f) { Player_Info.ableToDash = true; } if (timeForNextInvisiblity <= 0f) { Player_Info.ableToInvisibility = true; } if (immunityTimeLeft <= 0f) { immunity = false; } Vector2 move = Vector2.zero; if (!KeyImputManager.getMouvementLock()) { foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) { if (Input.GetKey(vKey)) { keyPressed = vKey; if (keyPressed.ToString() == KeyImputManager.GetKeyBind("Left")) { move.x = -1.0f; } else if (keyPressed.ToString() == KeyImputManager.GetKeyBind("Right")) { move.x = 1.0f; } if (keyPressed.ToString() == KeyImputManager.GetKeyBind("Jump") && grounded) { velocity.y = jumpTakeOffSpeed; } else if (Input.GetKeyUp(KeyImputManager.GetKeyBind("Jump").ToLower())) { if (velocity.y > 0) { velocity.y = velocity.y * 0.5f; } } if (keyPressed.ToString() == KeyImputManager.GetKeyBind("Defence")) { if (gameObject.name.Contains("knight_1")) { knight1Action(); } if (gameObject.name.Contains("knight_2")) { knight2Action(); } if (gameObject.name.Contains("knight_3")) { if (Player_Info.ableToInvisibility) { Player_Info.ableToInvisibility = false; decreaseOpacity(); isInvisible = true; Invoke("cancelInvisibility", Player_Info.invisibilityLenght); } } } if (keyPressed.ToString() == KeyImputManager.GetKeyBind("Left")) { if (isGauche == false) { collider = GameObject.FindGameObjectWithTag("SwordCollider").GetComponent <Collider2D>(); sprite.flipX = !sprite.flipX; collider.offset *= -1; } isGauche = true; } else if (keyPressed.ToString() == KeyImputManager.GetKeyBind("Right")) { if (isGauche == true) { collider = GameObject.FindGameObjectWithTag("SwordCollider").GetComponent <Collider2D>(); sprite.flipX = !sprite.flipX; collider.offset *= -1; } isGauche = false; } if (keyPressed.ToString() == KeyImputManager.GetKeyBind("Attack")) { attack(); } targetVelocity = move * maxSpeed; } } animator.SetFloat("speed", Mathf.Abs(velocity.x) / maxSpeed); animator.SetBool("grounded", grounded); } checkIfDefenceIsReleased(); }