C # Applying Velocity to Rigidbody

Hey all, I’ve got a bit of an issue here. I’m trying to add velocity to a gameObject so that after it has been moved it will just slowly come to a stop. I have to do it in C# and C# is a language that I dont have much experience with.

Below is the sample code that I’m using. Essentially, when the code inside “Input.GetMouseButtonUp(0)” is executed, I want velocity to be applied to the gameObject.rigidbody that has been moved.

private Vector3 movement;


protected GameObject pivot;
	
public override void handleSingleTouch(iPhoneTouch touch) 
{
	if (!allowDrag) return;

	movement = touchMovementVector(touch);

	  this.startPivot(gameObject.transform.position); 
		pivot.transform.Translate(movement,Space.World);
     if (Input.GetMouseButtonUp(0)) {
        gameObject.rigidbody.velocity = new Vector3(0, 10, 0);
		}
		this.endPivot();			

		
}

As it is, its moving the gameObject 10 for testing sake. Apologies if its something basic that I’m doing wrong, and I would appreciate any help. I have seen another question that is loosely related to my issue, but unfortunately it didnt help me much.

I think you may be wanting to use a different function than velocity to slow something over time.

The script reference for velocity is here

If you read the description, it is more suited to an instant change of direction, while using something like AddForce or AddRelativeForce would be for repeatedly “pushing” something.

You may also want to take a look at SmoothDamp, it smoothly translates a number from the current value to a target value (you could set as 0?).

You can use the script reference for Unity for looking up a lot of things. If you find the Rigidbody section it pretty much tells you all the functions it uses and you can have it show you how in C# or java.