2D Sidescroller - Player falls through ground

Hello,
I started recently a 2D sidescroller game. The first ever in my life. I’m totally new to unity and cSharp.

My scene is completely hand painted and I brought the layers into unity, assigned the z axis positions so far for the parallex scrolling. (But for the parallax scrolling I still got no script but I dont think that makes the problems at all.)
In the sorting layers the ground and the player got the same numbers assigned and the ground got a polygon collider, but when I hit the play button my player still keeps falling through the ground, and keeps endless falling…

Is there maybe something critical missing in my scripts or are there other reasons I’m not aware of?
I would appreciate any help and I’m sorry for my english it’s not my mother tongue.

Are you moving the player exclusively via his own Rigidbody2D physics and/or by using .MovePosition() on the rigidbody?

If you ever use transform.Translate() or transform.position = ... you will fall through stuff. The reason: doing so is a “teleport” from the physics standpoint.

Always let Rigidbodies do their own updating, OR if you must drive it, use .MovePosition() and/or .MoveRotation();

Thank you very much for your reply and your help!

I got the the 2D Controller Unity provided and with the rigidbody 2D it sems to work, but unlucky the jumping seems buggy. Sometimes it works, sometimes if you press jump nothing happens and the player keeps running right into the canyon.
Although the jumping doesn’t feel like something you want for a platformer at all.

I found today a free platformer Controller in the asset store which is the “2D Flexible Platformer Controller” from Yan it looks totally awsome to me, and got a lot of movements I was looking for, but sadly I don’t know if I could use his scripts only for the hand painted game I want to do. (His scripts are so many and I got a bit confused, if I would need all of them and how to get them working in my scene.)
I’m really sorry to ask such stupid questions, but I really want to get a hang of unity and CSharp and I would appreciate a helping hand to get the start done.

(Btw. he although wrote a note: works only with 3D colliders.The capsule shape used for the character controller does not work with 2D colliders.) So I’m not sure if I can use his Controller at all for the 2D game I want to make.

Code doesn’t care about art.

Excellent! What you want to do when learning is to strip out and simplify your problem space.

Put a single floor down, put your guy in there and start working on why the jumping is buggy. Or if that’s not enough to show the buggy-ness ,make the minimum level required to show the bugginess.

Once you have done that, time to start learning about how your code is actually running. This sounds hard but it isn’t, and the process will open up new folds in your brain you never knew you had.

This is my standard blurb to get started on the easiest way to understand your program, once you have done the steps above and simplified everything:

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also put in Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

https://discussions.unity.com/t/839300/3