Smooth movement rather than a snap movement

I want my character to move towards an enemy in my case and for that movement to be seen and smooth rather than it to be a button press and he is then automatically.

So like when a button is pressed it move towards the enemy like how enemys can move towards player or towrds waypoints. I know it something to do with the transform.position method or even translate and I’ve tried these but i still get a snap movement if you know i mean.

What is the right way to produce the type of movement I’ve described i’m looking to achieve. In the code below I’m using Vector3.Lerp and maybe I’m using it wrong , but in
the past I’ve used Vector3.MoveTowards and i still get the snap movement

Heres the code if you want to look at it:

function OnDrawGizmosSelected ()
{

    Gizmos.color = Color.green;
    Gizmos.DrawWireSphere (transform.position, radius);
    
    
    // Draws a blue line from this transform to the target
        Gizmos.color = Color.blue;
        Gizmos.DrawLine (transform.position, target.position);
    
}




function Update () 
{
    var controller : CharacterController = GetComponent(CharacterController);
    // gets the character controller and contains it information inside variable named controller
    var distance = Vector3.Distance(target.position,transform.position);
     startTime = Time.time;
 
    // Rotate around y - axis
    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    
    // Move forward / backward
    var forward : Vector3 = transform.TransformDirection(Vector3.forward);
    var curSpeed : float = speed * Input.GetAxis ("Vertical");
    
    controller.SimpleMove(forward * curSpeed);
    
    
       if(controller.isGrounded) // if the character controller is colliding with anything that is 
       // collidiable 
       {
           controller.height = standardHeight ;
           controller.center.y=0.05; // repositions the character controller to 0.05 on the y axis
           
           
         
        if (Input.GetButton("Jump")) // If the jump button is held down 
        {  
            moveDirection.y= jumpSpeed;
            controller.height = jumpHeight;
            controller.center.y=0.06;
           
           
           
        }
        
        }
        
        if(Input.GetButtonUp("Jump")) // If jump button has been pressed and released
           
        {  
            
           
           controller.height = middleHeight;
         
           controller.center.y =0.04;
           
           
              
        }
        
      
        
       
        
        
        if( jumpSpeed==70.0 && !controller.isGrounded )// if the jump speed if 70.0 and its not 
        // colliding with anything or not on the ground
        
         {
              if(Input.GetButtonDown("Fire2") && gravity ==90.0 && distance<radius)// if button has been pressed and released
              // and gravity at this point is 90.0 then do below
                  {   
                     if(Physics.Linecast(transform.position,target.position))
                     {
                          
                     
              var step = bouncespeed * extraspeed* Time.deltaTime;
              gravity =5.0;

             // Move our position a step closer to the target.
              transform.position = Vector3.Lerp(transform.position,target.position, step);
       
              animation.CrossFade("Bounce");
                   }
                   
                   
                   }
                   
                    
                    }
                    
                    
                    if(gravity ==5.0)
                    {
                      gravity =90.0;
                    }
                    
                 
                   
             
             
         
        
          
         
      
          
              
              
              
        
       
       
       
        
   
    
    
    
    controller.Move(moveDirection * Time.deltaTime);
    moveDirection.y -= gravity * Time.deltaTime;
}

Right now i’m trying to target an array of enemies in which you bounce attack the closest enemy then the second closest and so on i’m currently stuck because i have no errors and it doesn’t target any enemy’s anymore how would you go about moving towards the closest target then next

Referring to the solution-steps mentioned in this question, you should recheck for the closest enemy again (the same as how you get your first enemy) instead of using an array; it is much more cleaner that way.

Besides, using an array of enemies will have produce a not-closest-enemy problem, for example (I am using 2D position here):

In the scene, you are at (0,0), enemyA: (3,0), enemyB(-4,0), enemyC( 3,4). So the distance of A, B, C from you is 3, 4, 5 respectively. You store them in an array according to their distance from you, you will get { A, B, C }.

After you bounce and destroy A, your position would be (3,0), if you want to hit the next enemy in your array, it would be B; but B now is 7 unit away from you while C is 4 unit away. You should hit C instead, because C is closer to you in that point in time.

You should re-scan for the closest enemy every time you finish your bounce; then move on to that enemy if it is found, instead of storing your enemies in an array.