How to make arch knockback

So I want my character to be knocked back when it’s hit by an enemy. I tried to use this tutorial, Knockback & Stomping Enemies - Unity 2D Platformer Tutorial - Part 11 - YouTube. But it did not have the desired affect I was looking for.
This is the curve I am getting when the player gets knocked back with the code below. (don’t mind the height)
169573-not-right-curve.png

and this is what I would like.
169574-desired-curve.png

This is the code I currently have for the first curve.

if(knockbackCount <= 0)
{
    rb.velocity = new Vector2(input * speed, rb.velocity.y);
} else 
{
    if(knockFromRight && isGrounded == true)
    {
        rb.velocity = new Vector2(-knockback, nothing);
    }
    else if(!knockFromRight  && isGrounded == true)
    {
        rb.velocity = new Vector2(knockback, nothing);
    }
    else if(knockFromRight)
    {
        rb.velocity = new Vector2(-knockback, knockback);
    }
    else if(!knockFromRight)
    {
        rb.velocity = new Vector2(knockback, knockback);
    }
    knockbackCount -= Time.deltaTime;
}

Any help is welcomed, :slight_smile: thank you!

I think the reason why it has the not so desired curve is because you are slowing down in the air. If the horizontal movement stops in the air, it will fall straight down. Maybe you can try detecting if you are in the air; if you are, then continue to add a constant rb force until it touches the ground.

Hope this helps, I’m just 9 and found this online

I would suggest something like this that saves you from using coroutines, just remember to take control away from the player.
Call the Knockback() function from wherever you see fit (enemy script, a player health controller, etc.)

 void Update()
    {
        if (!isDead)
        {
            if (knockbackCounter <= 0)
            {
                //handle player movement according to your preference
            }
            else
            {
                knockbackCounter -= Time.deltaTime;
            }

            animator.SetBool("isGrounded", isGrounded);
            animator.SetFloat("YVelocity", theRB.velocity.y);
            animator.SetFloat("MoveSpeed", Mathf.Abs(theRB.velocity.x));
        }
    }

 public void Knockback(Transform other)
{
    knockbackCounter = knockbackLength;
    animator.SetTrigger("Hurt");
    theRB.velocity = new Vector2(0f, theRB.velocity.y);

    if (transform.position.x < other.position.x) //attack is comming from the right
    {
        theRB.AddForce(Vector2.left * knockbackForce, ForceMode2D.Impulse);
        theRB.AddForce(transform.up * knockbackVerticalForce, ForceMode2D.Impulse);
    }
    else //attack is comming from the right
    {
        theRB.AddForce(Vector2.right * knockbackForce, ForceMode2D.Impulse);
        theRB.AddForce(transform.up * knockbackVerticalForce, ForceMode2D.Impulse);
    }
}

}

After numerous tests to see why the rigidBody did not act going backwards basically forming an arc with these two functions:
rigidbody2D.addForce(Vector2.up * AnyValue, forceMode.Impulse);
rigidbody2D.addForce(Vector2.rigth * AnyValue);
I found that there was a crash for using rigidBody.velocity as an actuator in moveInput, that is, there was a conflict, the speed verification action on the x and y axis was disabled and it worked!
I hope it helps, I spent 3 days and a lot of talking with Gd hahaha.
Glory to Adonai!