# Raising an object to a certain point

How do you get an object to constantly move up and then stop at a certain point. I have been trying to get it to work by saying to stop when it hits a trigger but it just moves through. can somebody help me with a script?

Also have other little points along the way that the rising object will stop at for 3 or 4 seconds would also he very helpful.

``````var velocity : Vector3 = new Vector3(0,10,0);

var stopdistance : float = 30;

private var startposition : Vector3;

function Start()
{
startposition = transform.position;
}

function Update ()
{
if(velocity.x!=0 || velocity.y!=0 || velocity.z!=0)
{
var nextMove : Vector3 = velocity * Time.deltaTime;
var nextPosition : Vector3 = transform.position + nextMove;
var totalDistance : float = (nextPosition - startposition).magnitude;

if(totalDistance>=stopdistance)
{
//trim the final movement to stop at the proper distance.
nextMove = nextMove.normalized * (nextMove.magnitude - (totalDistance-stopdistance));

//Now set the velocity to zero so that we don't move any more
velocity = velocity * 0;
}

transform.Translate(nextMove);
}
}

``````