BOX HELP!!!

hey guys totally new at this programming thing, and I really need some help!

OBJECTIVE: Move an object around with a mouse click.
PROBLEM:
1)Need help with collision
2)I cant get my object to stop >.<

LANGUAGE: C#

Sorry if Im a total noob, but I would really like some advice on how to do this!

using UnityEngine;
using System.Collections;

public class moving_cube : MonoBehaviour
{

public float speed = 5;
Vector3 velocity = Vector3.zero;
// Use this for initialization
void Start ()
{

}

// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown(“Fire1”))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if ( Physics.Raycast(ray, out hit ) )
{
Vector3 dir = hit.point - transform.position;
dir.Normalize();
velocity = dir * speed;

}
}
transform.position += velocity * Time.deltaTime;

}
}

http://unity3d.com/support/documentation/ScriptReference/Ray.Ray.html

I think a Ray variable contains two Vector3…

Yes I have knowledge that Ray takes two arguments but when I pass in Input.mousePosition it acts as the two arguments. It gets the position in world space, and it already contains the direction in which the object is going towards. But yes I do understand where you are coming from.

Once again, I overlook some details (shame on me).

Can you explain again your problem, more precisely ? What is wrong with collisions ? Is your world is a flat surface ? Are there objects ?

And what do you mean by “your object won’t stop” ?

Im just trying to get this box to move to my click, and the object is not stopping.
Im not to worried about the collision, Im just wondering how I would go about making the object stop when It hits the destination

C# errors and other stuff nearly made me go bananas, so I tried it in US.

var speed : float = 5.0;

private var hasDestination : boolean = false;
private var destinationPosition : Vector3;
private var velocity : Vector3;

function Update ()
{
	if (Input.GetButtonDown ("Fire1"))
	{
		SetDestination (Input.mousePosition);
	}
	
	// Does the object has a destination ?
	if (hasDestination)
	{
		// The remaining distance between the object and the destination.
		var distanceRemaining : float;
		distanceRemaining = Vector3.Distance (transform.position, destinationPosition);
		
		// The length of a move this frame
		var velocityMagnitude = velocity.magnitude * Time.deltaTime;
		
		// Is the destination NOT reachable by a move this frame ?
		if (velocityMagnitude < distanceRemaining)
		{
			// Translate the farthest possible to the destination.
			transform.position += velocity * Time.deltaTime;
		}
		else
		{
			// Translate just enough to reach the destination.
			transform.position = destinationPosition;
			
			// Don't have anymore a destination.
			hasDestination = false;
		}
	}
}

function SetDestination (mousePos : Vector3)
{
	var ray : Ray = Camera.main.ScreenPointToRay (mousePos);
	var hit : RaycastHit;
	if (Physics.Raycast (ray, hit))
	{
		// Memorize the destination position.
		destinationPosition = hit.point;
		
		// Your stuff
		var dir : Vector3 = hit.point - transform.position;
		dir.Normalize ();
		velocity = dir * speed;
		
		// Memorize the fact the object got a destination.
		hasDestination = true;
	}
}

WOHOO THANK YOU VERY MUCH THIS HELPED ME A TON!!! The only thing that I changed was the function at the end. I just didn’t end up using a function. I converted the code to c# and WOHOO gots it. THANKS