Definitive Fix When Your Character Gets STUCK In Ground Tiles (Unity Basics)!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there i'm simon darsen and i'm the creator of a game called outlanderson today i'm shooting a very short video to show you how to fix your character from getting stuck in time maps in unity okay so first things first let's talk about when can this issue arise typically if you're using a box collider for your main character you can get stuck in corners of time maps for instance you might be using a box collider if you're quickly prototyping your game or even if your final character is a box like mine in this case you might get stuck okay so let's try to demonstrate this issue in play mode let's try to get our character to get stuck okay like right here so right now i'm holding left on my keyboard and this python left my character is stuck if we zoom in in the send view and i press left on the game view my character is stuck even though there is a gap between him and the time map quick note let's pause for a second and discuss the technical reasons why this bug is happening ok so we have a few tiles our character and the tiles collider highlighted in green the character is moving to the right and we have to look at what happens during collision with multiple corners which is the case right here the corner of the right tile is pushing the character to the left while the left tile is pushing to the top depending on how the collisions are resolved the relative collision might take priority resulting in the character getting stuck not good if you look up this issue online you might see people using a circle collider to solve this issue this prevents the character from getting stuck in corners but it's not great because now the character might jump slightly when running over a corner instead what we really want is to merge the tile together to have one contiguous collider this way our character will not encounter corners in between tiles anymore which was the source of the problem collisions are resolved as usual and our character can run over time without getting stuck yay so going back to unity we can achieve the same result of merging the colliders of each style of attack map by adding the composite collider to the component to the time-map game object when we add the composite collider to our game object a rigid body will automatically be added as well if there isn't one already since we are not going to move our tile map we can keep the body type static and then on the tilemap collider 2d you can just click on use by composite and suddenly all the tiles here are one collider with this change my character is no longer stuck in between tiles because there is only one collider and there is no way for the engine to make a mistake while computing the collision okay so that's the first fix but now you might notice that there is another problem see here my character is getting stuck on the ceiling even though he can jump higher than that he gets stuck same here here see we would expect the character to be able to fall off this ledge right but he is getting stuck and that's the same problem again if we zoom in we can see that there is some kind of gap because of the way that unity computes collision and because of this in this situation our character is stuck okay so this is also another easy fix what we can do is decrease the collider of our player and that's something that might be a bit counterintuitive in the beginning because you look at your character is with a box right of a size one by one which is the exact same same size of a tile and so you might think why would i change the collider because it's it's it fits perfectly right well actually it doesn't really fit perfectly if i start the game you can you can see that the character see how he moved up uh that's again because of the way that unity does collision okay so we can fix that and the way to fix that is to reduce the size of our collider so for instance for this character i already tried that and if you use point 95 for x and point 97 uh it's good values for a boss collider of one one i mean of a size of one one see how is perfectly lined up with the the tile right now that's because of this 97 and by the way if you want to test something else you can just change it for instance to 98 here and there is a very tiny gap now but this could work to be honest because you don't see that from far but you could also use 96 and now there is some kind of overlap between the sprites again the collider is not overlapping but the sprite is overlapping now because the sprite is bigger than the collider so let's go back to 97 which works perfectly here okay so now it works exactly the same as earlier instead except that now my character can easily jump in between tiles right same here i'm not stuck anymore so yeah that's basically it that's my two fix for your character getting stuck using tilemap and using a box collider character if you like the content make sure to subscribe to the channel for more content like this and make sure to check out my game out render son which is in development you can find links in the description to check it out thank you bye
Info
Channel: PrettyFrenchGames
Views: 6,243
Rating: undefined out of 5
Keywords: collision, unity, collider, tutorial, box collider, character, stuck, ground, tiles, 2D
Id: eJik78bWSg0
Channel Id: undefined
Length: 5min 53sec (353 seconds)
Published: Sun Oct 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.