I want to add a velocity of 10f while holding down S and if im not holding it down i want my rb.velocity to switch back to its default value.
if (Input.GetKeyDown (KeyCode.S))
{
rb.velocity = new Vector2 ( rb.velocity.x, -10f);
}
I want to add a velocity of 10f while holding down S and if im not holding it down i want my rb.velocity to switch back to its default value.
if (Input.GetKeyDown (KeyCode.S))
{
rb.velocity = new Vector2 ( rb.velocity.x, -10f);
}
if(Input.GetKey(KeyCode.S))
{
rb.velocity = Vector2.Lerp(rb.velocity,new Vector2(Mathf.Clamp(rb.velocity.x + 0.1f, 0f, 10f), rb.velocity.y), 1f);
}
else
{
rb.velocity = Vector2.Lerp(rb.velocity,new Vector2(Mathf.Clamp(rb.velocity.x + 0.1f, 0f, 10f), rb.velocity.y), 1f);
}
//The code is only for changing x velocity with āSā button pressed. If you want the similar behaviour in y velocity, do the same for y velocity.