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
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!