Question by
veleouist · Aug 24, 2021 at 09:40 AM ·
scripting problemrigidbody2dplatformergame development
Help! Can't make character get hurt and bounce back when hurt
Hello there! I'm trying to make a 2D platformer following a tutorial, and right now I'm a bit frustrated because I can't find the reason why my character doesn't getting hurt by an enemy, neither bounces back when getting hurt. Please help! (If you need another part of the code Lmk, I'm just a noob in coding) Thank you in advance. Here it is:
{
if (other.gameObject.tag == "Enemy" && state == State.falling)
{
if (state == State.falling)
{
Destroy(other.gameObject);
}
else
{
state = State.hurt;
HandleHealth();
if (other.gameObject.transform.position.x > transform.position.x)
{
//enemy is to right
rb.velocity = new Vector2(-hurtforce, rb.velocity.y);
}
else
{
//enemy is to left
rb.velocity = new Vector2(hurtforce, rb.velocity.y);
}
}
}
}
Comment