transform.Translate: object NOT moving toward RaycastHit problem

This is a test script i’m using to iron out bugs before i adapt it to use as a ‘shoot toward mouse cursor’ script.

Basicly, the script is on a cube (NO rigid body), and whenever the mouse cursor touches another object in the scene, the box is supposed to move toward the mouse cursor because the raycast is pointing to the cursor and the box is moving toward the raycast.

HOWEVER, the box moves in a seemingly random direction and NOT toward the mouse cursor (Grrr) Can anyone tell me where i’ve gone wrong?

function Update()
{

var hit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit))
{

transform.Translate((hit.point) * Time.deltaTime);

}

Thank you, Tom :slight_smile:

Transform.Translate needs a direction and not a location. So I guess this would do it:

     transform.Translate((hit.point - transform.position) * Time.deltaTime);