1
\$\begingroup\$

I'm working on a mechanic to allow the player to dodge through enemies. However I'm running into the issue where the player is only able to dodge through enemies while their already dodging when they collide with the enemy.

I want this to work both ways, as in, when their colliding with the enemy, they should be able to dodge through then.

Here's what I've been trying:

void OnCollisionEnter (Collision col) {

    //    STOP ENEMY FROM MOVING/PUSHING
    if (col.gameObject.tag == "Enemy") {
        Debug.Log("Collided with: " + col.gameObject.name);
        target = col.gameObject;
        target.GetComponent<ZombieController>().mRigidbody.isKinematic = true;

        //    IGNORE DODGING COLLISION WHEN ALREADY COLLIDED
        if (isDodging) Physics.IgnoreCollision(col.collider, GetComponent<Collider>(), true);
    }

    /*    IGNORE DODGING COLLISION
    if (isDodging && col.gameObject.tag == "Enemy") {
        Physics.IgnoreCollision(col.collider, GetComponent<Collider>(), true);
    }*/

}

It just doesn't seem to work when the player has already collided with the enemy. Hopefully all that made sense.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

You have to be prepared to avoid collision when the player is in dodging state even it it's not in collision / OnCollision(). Put a block like below on the Update():

if (isDodging)
{
    Physics.IgnoreCollision(GameObject.FindWithTag("Enemy").GetComponent<Collider>(),
                            GetComponent<Collider>(),
                            true);
}
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .