Bouncy character when landed on ground?

Hi,

My 2d character is bouncy when landed on the ground. It doesn’t look natural at all.

It has Rigidbody2d attached and a Box collider. Also the code that I use to move character is:
rigidbody2d.velocity

Is it has something to do with box collider or rigidbody2d? I have try changing a lot of option in rigidbody2d component such as Mass and Gravity but still the player is bouncing like he is has a ball.

You probably have a physics material assigned to the collider.

1 Like

No, It said none.
Can I see your rigidbody2d option? I turn on auto mass and it made no different.

Rigidbodies will not bounce unless they have a physics material or have a force added in code. Can you share the code that you’re using to move your character?

void Start()
    {
        _mySprite = GetComponent <SpriteRenderer> ();
        _myRigidbody = GetComponent <Rigidbody2D> ();
        _myAnimator = GetComponent <Animator> ();
    }

    void Update () {
        float clampZ = Mathf.Clamp (0, 0, 0);
        transform.localEulerAngles = new Vector3 (0, 0, clampZ);
        LimitY = transform.position.y;
        LimitOffset = LimitY - LimitY;
    }

    void FixedUpdate() {
        float deltaX = Input.GetAxis ("Horizontal") * Speed;
        Movement (deltaX);
        MyAnimator (deltaX);
        FlipCharacter (deltaX);
    }

    void Movement(float deltaX){
        _myRigidbody.velocity = new Vector2 (deltaX, _myRigidbody.velocity.y);
    }

I think it doesn’t has something to do with code. I just set the gravityscale to 10 and it not bound anymore but It feel hard.

Can you show me your Rigidbody2D and Collider2D settings? Also, can you show me the code that handles the jump velocity?

While there’s a bit of nonsense in your Update function, the movement code looks fine.

Just a tip though, if you want to make your life easier working with physics, you should let the physics system determine your velocity, and use “_myRigidbody.AddForce(deltaX, ForceMode2D.Impulse);” instead of setting the velocity directly. Then your Rigidbody2D’s drag property will slow your character down.

AddForce feel like Mario games.

AddForce feel like Mario games.

You’ve probably got the Rigidbody2D collision detection mode set to discrete. This means its colliders can overlap other colliders slightly (more the faster it goes) and then the physics system solves the overlap by moving it out. Sounds like this might be what you’re seeing and describing it as a bounce (which it technically isn’t as it doesn’t bounce away from the surface, only from an overlap).

If this is what you’re seeing, then you can use Continuous collision detection instead which is more expensive but stops overlaps and collision tunneling.

4 Likes

Thank you, mate. I can set back the gravity scale to 1 now.

1 Like

AddForce only feels like a mario game if you make it that way. If you set your Rigidbody2D’s drag value, you can make your character’s movement as slidey or stiff as you like. The reason it’s easier is because all the forces are combined and you get a resulting velocity rather than having to do all of that yourself, potentially fighting against the physics system by setting the velocity every frame.

I have a lot of problem with AddForce. I know it has something to do with drag, mass and gravity. I still prefer velocity because it simple except it can’t do a slicey movement or cool jump like AddForce.

I like to use a combination of the two. I generally use AddForce for almost everything, but I still set velocity to 0 sometimes or clamp the velocity manually when I need to.

You can actually achieve the same thing using your own calculations, like if you wanted a slidey feel you could make your movement keys add an acceleration to your velocity delta each frame, and letting go would be subtracting for deceleration, rather than setting the velocity instantly on key press and release.

In the end it does come down to personal preference, but it’s best to fully understand the options at hand before deciding.