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.

Question How to fix "bumping" motion when platforms (colliders) do not perfectly match height wise

Discussion in 'Physics' started by angeldevelopment, Mar 14, 2023.

  1. angeldevelopment

    angeldevelopment

    Joined:
    Sep 28, 2022
    Posts:
    52
    I am having a hard time getting around this, I have a generated runner type situation where certain prefabs don't align perfectly so the character has a bit of a bump when moving along a seemingly straight path.

    I have tried re-parenting the prefabs in question and changing their y transform, but this gets me nowhere.
    Adjusting their height will fix when the player runs onto that platform, but then when they leave that platform there will be a slight bump.

    I have tried messing around with the default contact offset, but I am pretty sure that only has to do with functions being called and physics reactions happening as a result of contacts. I am wondering how to smooth out this issue, as I have tried meticulously changing the height of the objects. This is a 3D project.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,361
    If the prefabs are like 3D blocks, then the issue happens because the character collides with the vertical face of the mesh. The possible workarounds I can think of are:
    • Remove the vertical faces of the blocks at the sides that are intended to be connected with another prefab.
    • Use a "floating" character that is not directly in contact with the floor, but a bit above it. This video explains how that solution works:
     
  3. angeldevelopment

    angeldevelopment

    Joined:
    Sep 28, 2022
    Posts:
    52
    My problems is that in my game te player runs along tiles which are separate objects (and they have to be)
    Although they are identical and at the same height, I suppose the player still collides with these vertical faces.
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,361
    Then the "floating" character approach described in the video would solve the problem as it wouldn't collide with the vertical faces.
     
  5. angeldevelopment

    angeldevelopment

    Joined:
    Sep 28, 2022
    Posts:
    52
    So i will have to apply a constant force in the y direction of my player to make them float, but eliminate this force when they jump? Wont this produce weird mechanics?

    Here is an image to give you some context
     

    Attached Files:

  6. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,503
    That's exactly what regular collisions do: apply an upwards force to the rigidbody when it's in contact with the floor, but stop applying it when it's not in contact. I don't think this will produce any weird results.
     
    angeldevelopment likes this.