Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Solved] Character gets stuck in floor

Discussion in '2D' started by Marcel-Kaemper, Oct 21, 2018.

  1. Marcel-Kaemper

    Marcel-Kaemper

    Joined:
    Oct 20, 2018
    Posts:
    9
    Hi,

    I'm creating a small 2D platformer as a first project.
    I applied a Material with 0 friction to my character so he won't stuck on walls. That works just fine, but the problem now is that he stucks in the floor for some reason. I can move a few pixels to the left and right before he randomly stops.
    I recorded that:


    Thanks in advance
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    box collider for the player and the platform is making from 3 parts ? then try capsule collider
     
    MEGEEE and Marcel-Kaemper like this.
  3. Marcel-Kaemper

    Marcel-Kaemper

    Joined:
    Oct 20, 2018
    Posts:
    9
    Sorry, I don't understand what you mean
     
  4. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    does your player have boxcollider2d ? In this case try to change the players collider to the capsulecollider2d. I can't see from the video if the collider is the problem.
     

    Attached Files:

    • box.png
      box.png
      File size:
      11.3 KB
      Views:
      1,724
    Last edited: Oct 21, 2018
  5. Marcel-Kaemper

    Marcel-Kaemper

    Joined:
    Oct 20, 2018
    Posts:
    9
    It works just fine with the capsule collider, thank you
     
  6. osamatarik05

    osamatarik05

    Joined:
    Oct 1, 2018
    Posts:
    1
    Thanks it also works well with me
     
  7. Emile123

    Emile123

    Joined:
    Mar 22, 2020
    Posts:
    1
    if i do this i dont get stuck anymore but my animations stop working, suddenly my jump or fall animation starts playing.
    please help
     
  8. DeadSk0ll

    DeadSk0ll

    Joined:
    Aug 15, 2020
    Posts:
    1
    Try setting the collider such that the collider's bottom matches with the player's bottom. Similarly for the other sides. It may then work
     
  9. MaximumSpice

    MaximumSpice

    Joined:
    Oct 25, 2018
    Posts:
    22
    Narukoopa18 and Kayckbr like this.
  10. D_MAS

    D_MAS

    Joined:
    Aug 28, 2019
    Posts:
    4
    using a capsule or circle collides creates another problem, you now slide off the edge, which is fine for 3D, but awful for 2D and fells hella unnatural especially when it kills your jumps when you try to make a running jump at the edge, which is something i can do effortlessly in most platformers
     
    raymondy1 and crooked4125 like this.
  11. ltlemur04

    ltlemur04

    Joined:
    Dec 31, 2020
    Posts:
    1
    What did the fix for me was using a BoxCollider2D with my player and then for my Tile Map I added the TileMapCollider2D and CompositeCollider component. The CompositeCollider will automatically add a RigidBody2D to your Tile Map. Set the RigidBody2D to static. On the TileMapCollider2D, check the box Used By Composite. Instead, of multiple colliders for your tilemap now unity recognizes it as a single collider. Credit to this tutorial:
     
    cballenar, Garfounkel and D_MAS like this.
  12. salahalhaddabi

    salahalhaddabi

    Joined:
    Oct 28, 2019
    Posts:
    1
    The Capsule collider is the solution to my platform as the blocks of the ground were making the enemies movement stuck after sometime. The player is fine with it's box collider.
     
  13. JasonTookTheAliens

    JasonTookTheAliens

    Joined:
    May 27, 2022
    Posts:
    1
    Now my player cant jump. Wy?
     
    tbriz likes this.
  14. tbriz

    tbriz

    Joined:
    May 13, 2014
    Posts:
    5
    I had this same issue... In the youtube video someone commented this, which fixed it for me:

    Change the composite collider geometry type from outline to polygon.

    For some reason, my character would sink below the outline of the composite collider, and would not jump, would basically get stuck in the floor. For whatever reason, changing to polygon just worked for me. Hope this helps.
     
    breylinlee likes this.
  15. KUNGERMOoN

    KUNGERMOoN

    Joined:
    Apr 29, 2020
    Posts:
    18
    For anyone in the future:
    Try decreasing the Default Contact Offset in Edit/Project Settings/Physics
    Changing it from 0.01 to 0.0001 worked for me

    Source
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,521
    Don't change the contact offset if you want stable collision detection for polygons. It's there for a reason and should only be changed if you understand the impact of it. Reducing it to the absolute minimum isn't a fix. You will not remove these kinds of ghost collisions, you'll only reduce them.
     
    jperman8 likes this.