Gravity and Bounciness Problem

I have a school project where I need to make a ball bounce off the floor. I am unsure how to enact gravity, bounciness etc. Anyone have a good place to start? My JS code so far is:

var velocity=-5;
var bounciness=.8;

function FixedUpdate ()
{
	rigidbody.velocity=Vector3(0,velocity,0);
}

This makes the ball drop until it contacts the “floor”, but I am unsure how to get it to “bounce” back up. I was thinking something along the lines off:
PSUEDOCODE:
if collides with floor
velocity=-(velocity*bounciness)

Then I would run into the problem of not having gravity pull it back down. Any ideas on how I could do this?

You might want to look at the book Game Physics Engine Development.

I understand the math behind it, I am just confused on how I can implement it with Unity and JS.

Here are the requirements if this helps:
Project Requirements:
Create a flat surface
Create a basketball (texture will be provided) that is suspended 20 meters above the surface
Set up physics variables that include velocity vector and a gravity vector, set to (0.0, -9.8F, 0.0), and a bounciness factor, set to 0.8F
The ball’s velocity and position are updated with each game frame
When the ball bounces off of the floor, its velocity vector is adjusted according to this formula:
velocity.y = -(velocity.y * bounciness)
When the ball bounces off of the floor, its position is reset to the floor’s height
Stop the ball’s movement when the ball’s total velocity is less than 0.2 and leave it resting on the floor
Capture user input for the Space key and use it to reset the simulation
Position the camera far enough away from the falling ball to easily see the entire ball drop/bounce sequence

Am I even on the right track?

Come on guys, this can’t really be that complicated. Anybody help?

Well, the physics engine does this itself, no need to code it. Just put a rigidbody and collider on your object, and make a physics material with 0.8 bounciness and set it to the collider.

Mik,

How do I go about setting bounciness? Is it with physicsMaterial.Bounciness? And if so, would this just look like:

physicsMaterial.Bounciness=.8

If you want to change it on runtime then yes, otherwise you can just make new physics material (in project view) and set the values there, and then assign it to your collider (select it in the ‘physics material’-slot in the collider component.)