Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Scripting' started by Eoghan, Apr 1, 2015.

  1. Eoghan

    Eoghan

    Joined:
    Jun 6, 2013
    Posts:
    80
    Hey Unity'ers! Apologies for the crosspost from General, but it doesn't look like anyone on there has had any experience with an issue like this before. Would greatly appreciate it if any of you in Scripting might have any insights into it.

    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?
     
  2. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    There is no need to use a collider for the character. If your camera angle is fixed like in the pictures, you can throw two rays to the ground, one from the back and one from the front of the character and detect any object with a collider.
     
  3. Eoghan

    Eoghan

    Joined:
    Jun 6, 2013
    Posts:
    80
    Would that really be the only way of doing that? It seems a little.. convoluted to draw a raytrace downwards and then "float" the player character on an imaginary floor, based on the fact that there's a floor within x units below them, rather than just having them manage to walk on the floor without getting stuck between tiles.
     
  4. Eoghan

    Eoghan

    Joined:
    Jun 6, 2013
    Posts:
    80
    Sorry to double-post, but I thought I'd share how I solved the problem without a raytracer approach.

    I simply changed the feet area box colliders to capsule colliders; now as we've got curved edges on the colliders themselves, the characters are fine to walk across these surfaces. No jaggy movements, or stuttering :)
     
  5. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    I would have mentioned that but just assumed you would already be using a capsule