How would I make a object flee from player?

I need help making a script that would make my object flee from the player. What I mean by this is when the player gets close enough to the object, the object will start moving away slowly from the player. I also need to make sure the the object doesn’t float in the air. I tried to fix this by adding a rigidbody and turned on gravity. For some reason it made my object move incredibly fast and fly off my terrain and before it did not do this.

So what I need is:

  1. Object flee from player

  2. Not float in the air/use gravity

  3. Face opposite rotation of player (objects back is towards the player)

My script that I have been using to test movement with my object is this, which follows the object instead of fleeing because it follows rotation with the player.

var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var attackRange = 15.0;
var moveSpeed = 5.0;
var Damping = 6.0;

function Update ()
{
	Distance = Vector3.Distance(Target.position, transform.position);
	
	if (Distance < lookAtDistance)
	{
		GetComponent.<Renderer>().material.color = Color.yellow;
		lookAt();
	}
	
	if (Distance > lookAtDistance)
	{
		GetComponent.<Renderer>().material.color = Color.green;
	}
	
	if (Distance < attackRange)
	{
		GetComponent.<Renderer>().material.color = Color.red;
		attack ();
	}
}

function lookAt ()
{
	var rotation = Quaternion.LookRotation(Target.position - transform.position);
	transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}

function attack () //Flees
{
	transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
}

Write this code. It should work. call it whenever you want your character to flee from the player.

void attack(){
    //C# scripting, you can easily convert to JS if you want
    Vector3 dir = transform.position - Target.position;
    transform.Translate(dir * moveSpeed * Time.deltaTime);
}

if anyone is still looking at this change the Vector3.forward to Vector3.back:

function attack () //Flees
{
transform.Translate (Vector3.back * moveSpeed * Time.deltaTime);
}