Click to move

I have the script working when you click he moves to point, and when you hold mouse button down he follows the mouse but when you hold your mouse for the character to follow if the mouse pointer is to close to the character it will act very weird with jerky movement or sometimes turn randomly. I sure it is something silly am over looking from staring at this to long.

webplayer : http://ihdlive.com/demo/myhackandslashtoon/WebPlayer/WebPlayer.html

Click to move script I am using

function Update () 
{        
        var vertical 	: float = Input.GetAxis ("Mouse Y") * mouseSpeedY * 0.02;
		var horizontal 	: float = Input.GetAxis ("Mouse X") * mouseSpeedX * 0.02;
        
        if(isControllable)
        {
	        if (Input.GetMouseButton(0)) 
	        {
	            ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	            
	            if (Physics.Raycast (ray, hit, Mathf.Infinity, clickableLayer)) 
	            {	            	
	            	currentSpeed = speed;
	            	moveDirection = hit.point;

	            	if(Vector3.Distance(transform.position, moveDirection) > playerClickRadius  Input.GetMouseButtonDown(0))
	            	{
	            		Instantiate(clickMarker, moveDirection, Quaternion.identity);
	            	}
	            }
	        }   
	
	        if (Vector3.Distance(transform.position, moveDirection) > playerClickRadius) 
	        {
	            var clickDirection = moveDirection - transform.position;	            
				clickDirection.y = 0;
				clickDirection = clickDirection.normalized;
				
				var rotation = Quaternion.LookRotation(clickDirection);
    			transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed); 
				transform.eulerAngles = Vector3 ( 0, transform.eulerAngles.y, 0 );
	        }
	        
	        clickDirection.y -= gravity * Time.deltaTime;        
	        characterController.Move(clickDirection * speed * Time.deltaTime);
	        
	        WalkAnimation();
	        
	        current_pos = transform.position;
	        current_pos.y = 0;
			var newspeed : float;
        	newspeed = (current_pos - last_pos).magnitude/Time.deltaTime;

        	last_pos = current_pos;
        }
        
        currentSpeed = newspeed;
}

You’re creating and assigning clickDirection only if the distance is greater than playerClickRadius, but you’re using it (on lines 35-36) regardless of that. Which would create odd effects when distance < playerClickRadius.

Thank you Errorsatz that was exactly the problem. I knew I had been just looking at this to long and over looked something.