Search Unity

Problems with character walking on platforms, built out of seperate cubes?

Discussion in 'Editor & General Support' started by Eoghan, Apr 1, 2015.

  1. Eoghan

    Eoghan

    Joined:
    Jun 6, 2013
    Posts:
    80
    Hey Unity'ers!

    I've noticed that in making a platformer, the player character (written up by myself) greatly dislikes it when platforms are made from several different blocks. Example;



    As you can see, this is a 5-block platform, with the pink quads on top being the walkable areas. The rest has a zero friction physics material attached, to allow the player to fall/slide down the side of it on contact. However, when the 5 quads are stuck together in that fashion (tested with no gaps, small gaps, and overlapping), the player character tends to get stuck/stutter between them.

    As a quick fix, when blocks are tied together in this fashion, I disabled their separate walkable areas, and replaced it with one large quad that covers over all of them, as seen below;



    This behaves perfectly as far as the character walking across them goes.

    Now, the problem is that I've written in a new script, where the player can "smash" these blocks (mario style), which also kills the walking area above it. However, with 5 blocks sharing one large walking zone.. this becomes a problem. Leave the walking area there, and the player can walk on air. Kill it entirely, and we're back to the old stutter problem.

    Right now, the only solution I have in mind is in the event of one block being smashed, I could instantiate new "walking areas" across the blocks that are still active. But this seems like a very far-flung solution to what's likely a very easily solved problem.

    Would anyone on here have any decent recommendations on how I can go about getting this working?
     
    BrandyStarbrite likes this.
  2. Eoghan

    Eoghan

    Joined:
    Jun 6, 2013
    Posts:
    80
    Just giving this a bump for the day-time crowd; if anyone has any suggestions, I'd much appreciate hearing them :)
     
  3. Franolich

    Franolich

    Joined:
    Feb 12, 2013
    Posts:
    6
    I've been having the same problem and, while I don't have a solution, I now have a better understanding of what is causing the problem. I used Debug.DrawRay() in OnCollisionEnter() and OnCollisionStay() to draw all the contact normals to the Scene View (see example below). I found that when first touching an adjacent platform, the contact normal was typically around 30 degrees off vertical. Clearly this is what's causing my player character to hop slightly.

    How to fix this is another matter and so far all I have managed to do is reduce the magnitude of the hops by lowering the player character's centre of mass. This may not work with your game's physics requirements but is okay for me as I also have a hinge joint restricting my player's movement to the surface of a cylindrical tower.
    Code (CSharp):
    1. rigidBody.centerOfMass = new Vector3(0f, someNegativeFloat, 0f);
     
    Last edited: Sep 6, 2015