pleas help with locomotion system and click to move

Hi i am building a small isometric style game, i am not very good with code so i decided to use the locomotion system for movement and animation, i want to move my character to where i click my mouse, this is working to some point, the problems i have are when the game starts the character starts running in a circle, he will move to the clicked point and start running in a circle again…

here is the code i am using

using UnityEngine;
using UnityEngine;
using System.Collections;

public class ClickCharacterController : MonoBehaviour {
    
    private CharacterMotor motor;
    private Vector3 targetPosition;
    private Vector3 directionVector;
    private Camera mainCamera;
    
    public float walkMultiplier = 1f;
    public bool defaultIsWalk = false;
    public float smooth = 0.0005F;
    
    void Start () {
        motor = GetComponent(typeof(CharacterMotor)) as CharacterMotor;
        if (motor==null) Debug.Log("Motor is null!!");
    }
    
    void Update ()
    {       
        // see if user pressed the mouse down
        if (Input.GetMouseButtonDown (0))
        {
            mainCamera = FindCamera();
            
            // We need to actually hit an object
            RaycastHit hit;
            if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  out hit, 100))
                return;
            // We need to hit something (with a collider on it)
            if (!hit.transform)
				return;
        
            // Get input vector from kayboard or analog stick and make it length 1 at most
            targetPosition = hit.point;
            directionVector = hit.point - transform.position;
            directionVector.y = 0;
            if (directionVector.magnitude>1)
                directionVector = directionVector.normalized;
        }

        if (walkMultiplier!=1)
        {
            if ( (Input.GetKey("left shift") || Input.GetKey("right shift") || Input.GetButton("Sneak")) != defaultIsWalk ) {
                directionVector *= walkMultiplier;
            }
        }
        
 		       // Apply direction
   		    Vector3 diff = targetPosition - transform.position;
    	    motor.desiredFacingDirection = diff.normalized;
        	motor.desiredMovementDirection = Vector3.forward;
        	transform.position = Vector3.MoveTowards (transform.position, targetPosition, smooth);
       	 	if (diff.magnitude < .1f)
        		{
            	transform.position = targetPosition;
            	motor.desiredMovementDirection = Vector3.zero;
       			}
    }

    
    Camera FindCamera ()
    {
        if (camera)
            return camera;
        else
            return Camera.main;
    }
    
}

any help with this or a better solution to do what i want to achieve would be great

Tazy

It seems alot of code for the one thing you want. I would suggest you need to isolate the one thing you want to do.

So, what do you want to do?
You want to click mouse, store position, have player move to that position.

Yeah thats all i really want to do, also using the locomotion system for the animations.

locomotion system

Tazy