2D RigidBody slightly penetrates objects causing a bounce effect.

So I am trying to set up a simple 2D platformer. I have Box colliders on my character and walls/floors. The collision is handled, just not correctly. When you collide with a wall, the character partially penetrates that wall, then the wall forces them back out causes a bouncing effect, and I can’t get the character to stop flush to a wall.

The effect is basically a vibration between the two pictures below. I also have a link to a video for further clarification.

alt text

alt text

Video of the Issue

***Note : amtToMove is a float set to 5;

void fixedUpdate()

{
	if(Input.GetKey("right"))
	{ 
		amtToMove = Input.GetAxisRaw("Horizontal") * playerSpeed * Time.deltaTime;

		//rigidbody.AddForce(Vector3.right * amtToMove);

		rigidbody.AddForce(Vector3.right * amtToMove,ForceMode.Impulse);
	}

	if(Input.GetKey("left"))
	{ 
		amtToMove = Input.GetAxisRaw("Horizontal") * playerSpeed * Time.deltaTime;
		rigidbody.AddForce(Vector3.right * amtToMove,ForceMode.Impulse);
	}

}

I have tried moving the character using Impulses, basic forces, and using basic translation. I am also handling the movement in the FixedUpdate() function.

I appreciate any and all help.

Hmm... just asking. Is it FixedUpdate() or fixedUpdate() ?

I am not sure about C# syntax or features, as I always use UnityScript. But in the scripting reference, FixedUpdate() is used with an uppercase first letter like the Update(), Start(), etc. I just do not understand why or how your fixedUpdate() is called... Unity or C# feature ? ^_^'

3 Answers

3

Go to your PhysicsSettings2D in Edit > Project Settings > Physics 2D. There is a field called Position Iterations… Change it to a higher number (maybe 5 or more). This should stop the bouncing.

I’m posting this to help others who run into this problem… Sorry if this isn’t an issue for you any longer.

Doesn't help at all. :-/

The only real solution to this problem is by lowering the Baumgarte Scale attribute in Edit → Project Settings → Physics2D to a very small value. With 0.0001 you will get no visual bounciness at all. I’d recommend a value that is slightly higher.

Thanks a million! your solution was really helpful. Was stuck the whole day

Thanks a lot, i got stuck at this problem for long time, even thought about writing my own 2d collision system.

The problem just got worse for me. I set the Baumgarte Scale to the 0.0001, but now the objects just permanently intersect. For some reason, my character's jump height also increased. Is there any way to resolve this?

Better to use a circle collider?

Circle collider vs box collider doesn't matter.