# TileVania 95: Move and flip enemy, not flipping

Hi!

I’m having a bit of trouble with making Goober flip directions. He’s willing to do it on the left side of the platform (where there is no wall) but refuses to flip on the right side, where there is a wall.
If I understand this correctly the Platforms Tilemap (which has the ground and the walls) has a Tilemap Collider 2D and is on the layer called ‘Ground’.

Goober has a Box Collider 2D, which I’ve placed a bit further to the right to make it more clear, that passes the red line (which is the collider line, right?). The Box Collider 2D starts on the collider, because it passes through the ground, Goober moves to the right, it passes through the wall collider and suddenly is not touching any of the colliders. Goober should turn left, but doesn’t do this, instead he runs right through the wall.

Goober runs inside of the wall, the boxcollider passes through to tilemap collider on the right side of the wall and Goober flips arond.

What am I doing wrong?

I’ve copy/pasted the script, to make sure it is right, but I can’t seem to figure this one out.

Hi MaartenvW,

Welcome to our community!

Thank you for sharing screenshots of the problem. That’s helpful. From what I see, Goober’s colliders seem to be correct. They are often the reason for this problem but, apparently, not in your case.

Another typical mistake is that the children of the parent game object (Goober) have got a significant offset. Please select the parent. While your game is not running, set the x-scale to -1, and then to 1 to see if you are able to recreate the problem.

If you are able to recreate the problem, click on the children. Their position in the Inspector is the local position relative to their parent. Ideally, there should not be any offset, so their position should be set to (0, 0, 0).

If you need an offset, place Goober right next to a wall and manually flip it by setting the scale to -1 and 1 respectively. Goober must not teleport but flip around its y-axis. Make sure that it does not end up inside the wall or on the edge collider when flipping. Otherwise, you’ll end up with a Goober constantly flipping around, or with the problem you are currently experiencing.

Did this help?

Hi Nina,

After fighting with Goober for about the entire weekend I decided to delete the Composite Collider 2D and the attached RigidBody 2D for the Platform Tilemap. Added the Composite Collider 2D again, along with the RigidBody2D and suddenly Goober DOES decide to turn around when hitting the wall. I’m pretty sure they both had the same values, but erhm… can’t explain this one

Anyways, thanks for your reply I appreciate you taking the time looking into it. In the end it was not a parent/child issue (as Goober is child/parentless) but a component mishap(?).

Good job on fixing the issue!

That might well be the case. If you hadn’t figured a solution out yourself, I would have asked you to share a screenshot of the TilemapCollider in the scene. In some cases, the collider shape does not get calculated correctly, which is not your fault but a problem with the collider itself. We would have seen (random) gaps. The problem might have been caused because of those gaps. The gaps consist of at least one edge, which causes Goober to flip.

Usually, disabling and reenabling it makes Unity recalculate the shape. Removing and readding the collider is an alternative way.

Since I don’t know the details in your project, this is just a guess, though. If you encounter this problem again, maybe in another scene, check the collider shape first.

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