So I want my character to be knocked back when it's hit by an enemy. I tried to use this tutorial, https://www.youtube.com/watch?v=sdGeGQPPW7E. 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)
![alt text][1]
and this is what I would like.
![alt text][2]
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, :) thank you!
[1]: /storage/temp/169573-not-right-curve.png
[2]: /storage/temp/169574-desired-curve.png
↧