Hey everyone, I'm trying to solve this issue since nearly 6hours without any success..
I hope someone can help me, I tried to use AddForce on a GameObject (Enemy) to push it back by hitting it, the following script is implemented in a Knockback Class which is attached to the enemy
but when I hit it, it get's teleported and don's "slide" to it's position
I hope this time someone help me, never got an answer to any of my questions... =(
public Vector3 moveDirectionPush;
public Rigidbody2D EnemyRigidbody;
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Enemy")
{
moveDirectionPush = EnemyRigidbody.transform.position - other.transform.position;
EnemyRigidbody.AddForce(moveDirectionPush.normalized * 300f);
//damage dealing and effects
}
}
↧