Gravity problem in my first 2D game

Hello,
I’m working on my first 2D side-scrolling game, I used several tutorials and tried several things but now I have a behaviour that I don’t understand. I have a tilemap, I added a Collider 2D, I dropped my player just above the floor with the collider.

My player has a “Box Collider 2D” and a “Rigidbody 2D” where I’ve set “Simulated”=“on”, “Use Auto Mass”=“off”, “Mass”=1 and “Gravity Scale”=1. It is not clear to me what those options do exactly.

When I hit play, the player.transform.y goes -1. The player moves with left and right but doesn’t jump. If I unset “Simulated”, player doesn’t drop -1 but doesn’t move left and right anymore.

To move the player around, I use:

Vector3 targetVelocity = new Vector2(_horizontalMovement, _verticalMovement);

rigidbody2D.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref z, .05f);

if(isJumping)
{
    rb.AddForce(new Vector2(0f, jumpForce));
    isJumping = false;
}

Would you have any idea what can be the cause of this dropdown ?

Thanks.

What is the desired outcome? Do you want the player to be affected by gravity or not? Your player isnt jumping cause of the code. Throw in a Debug.Log to make sure that the function inside of the if(isJumping) is running. If it is calling, then make sure the value of jumpForce is high enough to actually make the character go up.

If that doesnt work, then i suggest following a tutorial video like this:

Thanks a lot ! Awesome tutorials !!

One of the issues was that I changed by mistake, the default value in Project Settings > Physics 2D > Gravity > Y. I had set it to 0 which unbalanced all gravity stuff !!!

I leave this here so it might help a poor soul :slight_smile:

Lol yeah that might hurt things. You can change that value in code too. You can either change the character’s gravity value or everything’s.