Hazard and Enemy Issue

So I have noticed two issues with enemy movement.

Issue 1: Water Hazard

If you have an enemy right next to a space that has a water tile in it, you create the same flipping issue that Rick attempts to solve by making it an “is trigger”

Issue 2: When hitting an enemy

Sometimes I have hit an enemy at an angle and noticed that this will cause the enemy to switch directions mid movement, without colliding into platform tiles.

I’m uncertain how to fix either of these issues. I will attempt to take a short video of each problem and post them within this post.

Hi Drakken666,

Thank you for the video. That was helpful. :slight_smile:

To me, it looks as if the two issues could be related. For this reason, start with issue 1. When the enemy gets stuck like at the end of the video, pause your game. Then zoom in on the enemy in the scene view. Select the enemy in the Hierarchy if you haven’t already, so you are able to see its colliders.

Then click the button on the right side of the pause button to flip through the frames. You will very likely see that the enemy’s body collider touches the edge collider of the platform. The solution is to move the periscope collider a bit farther away from the enemy, so the enemy does not touch the edge again when flipping around.

Or maybe you will see something else. Analyse the situation by flipping through the frames, and you’ll probably come up with a solution yourself.

If you solved problem 1, and problem 2 persists, do the same again, but this time pause before the enemy touches the player.

Did this help? :slight_smile:


See also:

It did not as I had already done that as described in the tutorial. What I believe it stems from is that both with the water (hazard) and the players “feet” rigidbody are both triggers and is making something weird happen. I just dont know how to fix it.

I must have missed that part. Could you please point me to the second where I can see the colliders in the scene while your game is running and where you are flipping through the frames?

Your assumption what the problem might be is a good start but the next step is to verify that assumption. In the end, believing is not knowing. I would highly recommend to try what I suggested.

If you verified that the problem is indeed that both collider are triggers, you could do what we did in the Delivery Driver game or here in the TileVania game: either check the ‘other’ tag or the layer before executing the code.

When I say tutorial I mean the tile Vania course. Not the video I made. Whatever I’ll try and mess around with it.

If you meant the tutorial and saw things in the tutorial but those things do not work in your project, I would suggest to rewatch the relevant videos and compare your settings to Rick’s. It is easy to miss a detail or do move the periscope collider too close to the enemy’s body collider.

So it appears that the issue with the water is that we have the periscope going below the ground to check to make sure that we aren’t falling off ledges, and that interacts with the water hazard. I’m not sure of a solution for this but can move past it for now.

As far as the Issue 2 I made another video of a frame by frame that hopefully you can help me fix.

I’m not sure if the solution would be to change the collider on the player as well, or if it stems from there being 2 triggers interacting with each other. Which would make sense as that is also what I think the issue with the water hazard is. Because other then that the enemy operates fine.

Truly appreciate youre help

So I missed the using other.tag part and changing the ontriggerexit2D to :

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

And this solved the issue! Thank you so much for being patient and helping me through it!

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

Privacy & Terms