So I’m working on part of a script that knocks the player back after being hit by an enemy. However, if you press any of the movement keys (A or D)… Basically you won’t be going anywhere. I was thinking I could disable the movement while being knocked back, and as soon as the player hits the ground, re-enable it. Here are the parts of the script in question:
var hurt:boolean = false;
function OnCollisionEnter2D(collision:Collision2D)
{
if(collision.gameObject.tag == "Enemy")
{
hurt = true;
var relativePoint = transform.InverseTransformPoint(collision.gameObject.transform.position);
if(transform.localScale.x == 1)
{
if(relativePoint.x < 0.0)
{
rigidbody2D.velocity.x = 6;
}
if(relativePoint.x > 0.0)
{
rigidbody2D.velocity.x = -6;
}
rigidbody2D.velocity.y = 4;
}
if(transform.localScale.x == -1)
{
if(relativePoint.x > 0.0)
{
rigidbody2D.velocity.x = 6;
}
if(relativePoint.x < 0.0)
{
rigidbody2D.velocity.x = -6;
}
rigidbody2D.velocity.y = 4;
}
//Wait until grounded == true
//Then do this:
hurt = false;
}
}
Then I added " && !hurt" to the if statements concerning left/right movement.
Anyways, see the commented part of that code. Any idea how I could do that? If I put it in a regular if statement, it won’t work, presumably because you’re on the ground when you’re actually hit.