Click to move script help

I don’t really get what I’m doing wrong. I’m new to scripting and am determined not to just use packages, as I do want to learn to script. There are no error messages and the x, y and z variables of dest don’t change when I click. Could someone give me a rundown of what I’m missing please?

#pragma strict

var dest : Vector3;

function Update () {
if(Input.GetKey(KeyCode.Mouse0)){

  var hit : RaycastHit; 

  var ray : Ray = camera.main.ScreenPointToRay(Input.mousePosition);


  Debug.DrawRay(ray.origin, ray.direction*10,Color.yellow); 


  dest = hit.point;

  Vector3.MoveTowards(transform.position,dest,10*Time.deltaTime);

} }

I think you are missing using an actual raycast. You are creating the ray, however you are not casting it out and calculating the hit point.

Add in the following after the line which starts var ray:

Physics.Raycast(ray, out hit);

That should hopefully solve your problems. If not, post again and I’ll see if I can find out some more :slight_smile: