Move toward Mouse Cursor (RaycastHit), without following?

So with some help from you great people, i have ‘finished’ this script:

function Update () {

var hit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit))
     {
 
 transform.Translate((hit.point - transform.position) * Time.deltaTime, Space.World);
 
 transform.position.z = Mathf.Clamp(transform.position.z, 0, 0);
 
 }

}

This is applied to an instantiated ‘bullet’ which then moves toward the cursor, but it naturally follows the cursor as it moves.

Where would i begin looking if i wanted it to move toward the cursor direction, and then CONTINUE in that direction without following the cursor?

The ‘object’ the raycast is hitting is a plane with the mesh renderer taken off.

Thanks for your brain-power, Tom :slight_smile:

Try something like this:

var direction: Vector3;
var speed : float = 2;

function Update () {

var hit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit))
     {
          direction = (hit.point - transform.position).normalized;
     }


 transform.Translate(direction * Time.deltaTime * speed, Space.World);
 transform.position.z = 0;

 
 }

}