Enemy flips when bumping into the player

Hi,

In my settings, the enemy flips itself when the player runs into the enemy. Please see the attached video. Any help is appreciated. Thank you!

Hi Liam,

Thank you for your video. What is supposed to happen?

Looking at Rick’s video from https://www.udemy.com/course/unitycourse/learn/lecture/28740580#overview, the behavior from his video is that the enemy pushes the player along the way.

Are the colliders set up correctly? For example, are the same colliders triggers/non-triggers as in Rick’s case? Is the relative position of the colliders the same as in Rick’s game? Did you use the same methods?

The enemy’s “periscope” collider makes the enemy flip. It must be touching the ground collider all the time. If the collider exits the ground collider, the enemy flips.

Thanks Nina,

yea, you are right. The below code seems to make flip work as shown in the Rick’s video.

   void OnTriggerExit2D(Collider2D other)
    {
        if (other.tag == "Player") { return; }
        moveSpeed = -moveSpeed;
        FlipEnemyFacing();
    }
1 Like

Does the flipping still happen? If so, check the player’s tag. Maybe it is not “Player”.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms