2D Physics problems - Bounciness & Gravity

Hey guys,

So I’ve been testing out some 2D features in Unity as I’m aiming to create a 2D game. So far, it’s wonderful - my last 2D endeavor entailed hand-coding my sprite animation…not fun.

I am relying heavily on physics & 2D rigidbodies in this. My main character is moved using AddForce(). Since I want my character to have a pretty quick jump/land, I have gravity set to -100 (instead of the standard -9.81). The intense gravity setting was done as per suggestion from the actual Unity 2D tutorial video, and I like the response it gives me; however, I’ve run into a problem.

With rigidbodies that contain bouncy materials, the intense gravity causes them to bounce/jitter indefinitely when they should be asleep.

I have a circle collider with rigidbody properties tweaked so it behaves how I like it, with bounciness: 0.5 and friction: 1. The physics properties of the ground are friction: 1 and bounciness: 0. I’ve concluded that the intense gravity and the level of bounciness cause the object to have an indefinite bounce, but I cannot find a way to overcome it!

Here’s what I’ve tried:

  • Increase linear drag on bouncing object - stops bouncing, but also doesn’t allow the object to move much/at all.
  • Change mass on bouncing object - nope. Nothing.
  • Change gravity scale on bouncing object - obvious solution to jitter problem, but then this object behaves as it would on the moon while everything else behaves normally, resulting in non-uniform gravity.
  • Change bounciness - then it doesn’t behave how I’d like it to!
  • Alter Interpolate settings, Sleep Mode settings, Collision Detection settings…no luck
  • Decrease Physics/Physics2D settings for gravity - then I lose the quick jump that I like.
  • Alter physics properties of the surfaces it bounces on - nah.

After a few days of trying every possible combination of these things, I can’t seem to get it straight. I’m at a loss for ideas, Unity community…and I need your help!

I’ve included a link to the video below. If you don’t have any suggestions, then I hope you’ll at least enjoy my cat! :-3

Video: Video Here

You could set the Velocity Threshold from Physics2DSettings to a higher value. It worked for me.

Well, here’s one solution I came up with, that you could build upon. Instead of using a bouncy material, do it through scripting.

private bool grounded; //I'm guessing you have a grounded var by now, right?
private float velY = 0;
public float bouncePower = 5f;
public float minVelBounce = -3.0f; //minimum velocity we must be going faster than, to trigger a bounce, so we don't bounce for infinity

void FixedUpdate()
	if (!grounded)
	velY = rigidbody2D.velocity.y; //we do this only if we aren't grounded, so that when we do OnCollisionEnter2D, we have our velocity before collision stored for various uses

	void OnCollisionEnter2D(Collision2D colObj)
		if (colObj.gameObject.tag == "Ground")
			if(velY < minVelBounce)
				rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x,((velY * -1) * 0.2f) * bouncePower);
				velY = 0;

Adjust the division amount before the bouncePower to tweak how much you want the velocity.y to affect how much you bounce when you land.

It basically just stores your velocity.y before you hit a ground collider, and once you hit it, if you’re moving fast enough downward to meat the minVelBounce threshold, then your velocity.y will be set to that stored velocity, divided a bit to bring it’s value down and then multiplied by your bounce value. Will need some tweaking though, maybe some better math too.