Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Question Why is my 2D character getting pushed down 0.544207 in Y when uncrouching below a passable platform?

Discussion in 'Physics' started by Reverend-Speed, May 23, 2023.

  1. Reverend-Speed


    Mar 28, 2011
    I have a 2D platformer (using OpenGameArt sprites), where the character needs to be able to crouch AND be able to press crouch and jump in order to drop down 'thin' platforms.

    I'm using two Tilemaps (Midground and OneWayPlatforms) on two respective different layers (Ground and OneWayPlatforms).

    When dropping down, I use Physics2D.IgnoreCollision to temporarily ignore the OneWayPlatforms TilemapCollider2D.

    When standing up from a crouch, I BoxCollider2D cast to make sure nothing on layer 'Ground' is above the character's head before the character stands up.

    However, when standing back up from a crouch while standing on a OneWayPlatform with a OneWayPlatform above my character's head, instead of standing up on the lower platform while the upper platform is now at the character's waist (expected behaviour), my character is pushed 0.5442 units down until their vertical halfway point (waist) is now level with the lower platform - effectively, they're pushed halfway down through the lower OneWayPlatform.

    I've tried adding some Y velocity and/or teleporting up a few centimetres (transform.position += (Vector3)Vector2.up * 0.5) coming out of the crouch but either it causes the character to fall down through the platform or the character just ends up getting stuck in the platform as before.

    Can anybody suggest to me why this is happening? This is really baking my noodle. - Basic V movement (includes 'crouch' code) - Specific drop-down code