how do i write this: apply a negative force value on my object (to make it slow down its velocity), but i don't want it to go past 0, which ends up making the object travel in reverse.

can't seem to find answers related to this, there's some questions up but no answers to them.

again, i'm a game artist, starting out to learn to script, so i'm looking for help, and best if i get pointed in the right direction and where to look and what to look at to solve my current problem.

after writing my code (i'm trying! learning alot already, coming from zero c# background), i am now getting this error:

Assets/Booster.cs(34,27): error CS1955: The member `UnityEngine.ConstantForce.force' cannot be used as method or delegatecannot be used as method or delegate

here's what i have so far written:

using UnityEngine;
using System.Collections;

public class Booster : MonoBehaviour {
    //private vehicle = GameObject.Find("vehicle"); //obtain a reference to the object with the script attached
    //private constantForce = vehicle.GetComponent<engine>(); //obtain a reference to the script itself
    //private currentSpeed = constantForce.force; //copy the value of the life variable to a local variable
    public GameObject target;

    // Update is called once per frame
    void Update () {

    }

    void OnTriggerEnter () {
        Boost();
        StartCoroutine(Slowdown());
    }

    private void Boost(){
        //Engine e = target.GetComponent<Engine>();
          //You don't need a cast, that the whole point of generics.
          //I don't think you need this either.

          ConstantForce motor = target.GetComponent<ConstantForce>();
          //You needed an instance.
          motor.force = Vector3.forward * 500;
          //Hard-coded values are generally not good.
     }

    IEnumerator Slowdown(){
        ConstantForce motor = target.GetComponent<ConstantForce>();
        yield return new WaitForSeconds(5);
        if (motor.force ("0")){
        motor.force = Vector3.forward * -250;
        }
    }
}

my error above is after i tried adding the "if" statement at the Slowdown function. I'm trying to make it check to make sure the object does not get pushed backwards into the "negative velocity" which makes it travel in reverse. like it's going from 10, to 0, then to -10. i don't want it to go down past 0 into "reverse".

the best thing now is if i'm able to write it so that it returns to it's original velocity, prior to "slowdown". like it's traversing at say 1000 before my Boost function, after the Boost function i want to slow it back down to the original speed after a certain period of time.

big thanks to anyone that helps!

Just set rigidbody.drag to something greater than 0 that will slow it down. The bigger the value faster it slows down.

edit

Just saw your that you've got an error message.

Assets/Booster.cs(34,27):

In brakets behind the scriptname you can see the linenumber and the column where the error have been spoted.

if (motor.force ("0"))

That won't work because you used the variable like a function. You want to check if the force is 0 but to check a variable you need a compare-operator like == or >= or <=

Next problem: motor.force is a Vector3. That means it has 3 values X,Y and Z. You can't compare a Vector3 with a single number but with another Vector3.

That's all possible:

// check if the force is 0,0,0
if (motor.force == Vector3.zero)

// magnitude calculates the length of the vector which is a single number and can be compared with 0
if (motor.force.magnitude == 0)

But as i mentioned above you should use drag to slow it down. Drag represents friction like forces that gets automatically applied by the physics system.

second edit

Just realised what you want to archive. It seems you use a rigidbody, otherwise ConstantForce wouldn't make any sense. A rigidbody moves with it's velocity. A constant force will apply an acceleration on the rigidbody what will make it moves faster and faster because the velocity increases. I don't know how you move you object "normally". If you want to check the speed / velocity of your object you have to look at rigidbody.velocity. The force property of your constantforce component you tried to check will never change unless you set it to something else.

Can you give us some more information what kind of object we're talking about? A player that moves on the ground? How is the movement implemented? Do you use a CharacterController?

third edit

To give a rigidbody a single immediate boost just do this:

float boostValue = 20; // adjust to your needs

private void Boost()
{
   rigidbody.velocity += transform.forward * boostValue;
}

that will increase the velocity by boostValue and the rigidbodys drag bring it back down slowly automatically.