Character Falling Through Floor

Home Forums Books Mastering Unity 2D Game Development Character Falling Through Floor

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #9722
    Adam Roberts

    Hi Simon,

    I caught an error in my Player object…I had all of the transform positioning applied to the attached PlayerSprite, but not the Player Object itself.

    To fix, I adjusted the transform values to the Player object and zeroed out the Sprite transform, and now my character falls through the floor on start-up.

    As far as I can tell, that’s the only change I made. Any idea what I’m overlooking?

    It occurs to me that the problem could also be with the CharacterMovement script too, so that’s where I’ll be digging until you get a chance to reply.

    Thanks for your time!

    Adam Roberts

    Changing around the CharacterMovement script isn’t fixing things. I imported yours from the sample code to no avail.

    New info though…it seems to be with RigidBody2d or an interaction with it. When I remove the RigidBody2d component from Player, the character no longer falls. I assume this is a Unity Physics (Gravity) behavior.


    Adam Roberts

    One more bit…if I zero out the y transform on the Player object, the falling behavior disappears. Up to -1, I’m fine.

    Anything greater than that and the character starts to fall. Weirdly, the falling is faster the farther down from -1 I get…so a y transform of -1.1 fell really slowly. -2.5 was really fast…

    I can adjust the PlayerSprite without issues. Its only the Player Object that falls when below -1y



    Hi sorry for not getting back sooner.

    The RigidBody enforces gravity but as we set the Gravity Scale to 0, gravity should have no effect.  The movement script only moves the player left or right.

    So it’s curious as to why your character is falling when there is no force being applied to it.

    You say you moved the rigidbody component from the sprite to the player, can you confirm it was removed from the sprite?  Only reason I can think of why it should just fall if one game object in that hierarchy still has a rigidbody with gravity applied.

    Could you zip your assets folder and post it on dropbox or other file share for me to look at and we’ll see what’s happening.




    Simon (Darkside) Jackson

    Adam Roberts

    RigidBody2d is only attached to the Player object. The Sprite has Transform, Renderer, and Animator.

    Here’s my Asset folder. Thanks for looking into it!


    Ohhh, that was fun and did have my head scratching for a few minutes until the lightbulb moment.

    So, one thing you have to remember is that ALL objects that have a rigidbody will be affected by physics motion like gravity.  Objects with a box collider will be affected by other objects with colliders impacting them, usually by stopping them in their tracks like a wall (unless the collider is a trigger, in which case it will just set off an alarm).

    However if one object has both a box collider AND a rigidbody, impacts with another object with a collider and a rigidbody then physics will be applied by those two objects colliding.

    Let that sink in and look at your scene.  Answer further down the page.








    Your wizard is standing on your players head 😀 and has gravity applied.   Hence he pushes the player down.

    I tried creating a new player and sprite, applying collision and the rigid body to it, with gravity it dropped, without it didn’t.  Rest the players gravity in case it was some weird new Unity bug and then spotted it.


    I must say that was the most fun issue I’ve come across and it made me smile when I finally figured it out.  Much better than a typo in a script.

    I wish you well on your Game Dev journey and if you have any other issues please do reach out.


    Simon (Darkside) Jackson


    Haha! That was awesome! I hadn’t even dug down to the Wizard because of the weirdness with the Player. So glad you caught it…I was totally stumped.



    No worries, glad to help.

    Simon (Darkside) Jackson

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.