Rigidbody2D.Addforce results in unrealistic force

So i’ve spent a lot of time trying to figure out how to code the bounce into unity, but i can’t seem to find the best answer related to this case. I hope i can explain as much as possible.

Ultimately what i would like is to have the exact bounce that physics material ‘Bounce’ gives you. The only problem is that you can’t control any of the factors, and it’s maximized to 1, which isn’t nearly enough. Also it just stops bouncing after a while so that doesn’t really work as well :confused:

At the moment i’ve got the following:

void OnCollisionEnter2D()
	{
	projectile.rigidbody2D.AddRelativeForce (Vector2.up * 1000, ForceMode2D.Impulse);
	}

Projectile is a public variable, and is just a ball. The collider is a straight EdgeCollider2D.

As you can imagine, this just propels the projectile upwards, without taking into account from which direction the projectile collides with the EdgeCollider2D, so it doesn’t ‘bounce’ off of it. It just launches it straight into the air, which is really funny but not really the thing i’m looking for.

My question is, what is the best way to script this? Should you use rigidbody.velocity instead? If so, do you let unity calculate the current velocity and invert it? I hope someone can help!

For future knowledge, anyone having the same problem, i fixed the above with the following code:

	void OnCollisionEnter2D(Collision2D collision)
	{
		foreach (ContactPoint2D contact in collision.contacts) {
			Debug.DrawRay(contact.point, contact.normal, Color.green, 10, false);
			Debug.DrawRay(contact.point, -contact.normal, Color.red, 10, false);
			Vector2 force = -contact.normal * 500;
			projectile.AddForce(force, ForceMode2D.Impulse);
	}
}

Projectile is in my case defined as a public Rigidbody2D and dragged into scene. Hope that helps someone!