Help fixing AI?

So my AI works pretty well right now, but there are things I want it to do that wont work with the code I have later on. Im am currently moving it towards the player using transform.translate, but I want to switch it to velocity so it wil have collision and i will be able to mak things like knockback. Although, I dont have any real idea how to switch it velocity from here, so I was wondering if anyone could help me out. (I assume its pretty simple but I cant seem to figure it out)

Heres my enemy AI script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GruntAI : MonoBehaviour {

public float moveSpeed;


public float shootSpeed;

private bool inRange;
private bool canGen;

public float patrolArea;


private Transform playerPostion;

private Vector2 randPosition;

private Rigidbody2D rb;

// Use this for initialization
void Start () {
    playerPostion = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();

    inRange = false;
    canGen = true;

    randPosition = new Vector2(Random.Range(patrolArea * -1, patrolArea), Random.Range(patrolArea * -1, patrolArea));

    rb = GetComponent<Rigidbody2D>();


}

// Update is called once per frame
void Update () {

    if (inRange == true)
    {

        transform.position = Vector2.MoveTowards(transform.position, playerPostion.position, moveSpeed * Time.deltaTime);

        

    } else
    {

     transform.position = Vector2.MoveTowards(transform.position, randPosition, moveSpeed / 2 * Time.deltaTime);

    }

    if (canGen == true)
    {
        StartCoroutine(generatePosition());
    }

    
    
}

private void OnTriggerEnter2D(Collider2D other)
{
    if (other.tag == "Player")
    {
    inRange = true;

    }
}

private void OnTriggerExit2D(Collider2D other)
{
    if (other.tag == "Player")
    {
        inRange = false;

    }
}

IEnumerator generatePosition()
{
    canGen = false;

    randPosition = new Vector2(Random.Range(patrolArea * -1, patrolArea), Random.Range(patrolArea * -1, patrolArea));

    yield return new WaitForSeconds(1);

    canGen = true;
}

}

Hi, try with this:

    public float moveSpeed;

    public float shootSpeed;
    private bool inRange;
    public float patrolArea;

    private Transform playerPosition;
    private Vector2 randPosition;
    private Rigidbody2D rb;

    // Use this for initialization
    void Start()
    {
        playerPosition = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
        inRange = false;
        randPosition = new Vector2(Random.Range(patrolArea * -1, patrolArea), Random.Range(patrolArea * -1, patrolArea));
        rb = GetComponent<Rigidbody2D>();
        InvokeRepeating("generatePosition", 0, 1);
    }

    // Update is called once per frame
    void Update()
    {
        if (inRange == true)
        {
            rb.velocity = (playerPosition.position - transform.position).normalized * moveSpeed * Time.deltaTime;

        }
        else
        {
            rb.velocity = (new Vector3(randPosition.x, randPosition.y, 0) - transform.position).normalized * moveSpeed * Time.deltaTime;
        }

    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            inRange = true;
        }
    }
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            inRange = false;
        }
    }
    public void generatePosition()
    {
        randPosition = new Vector2(Random.Range(-patrolArea, patrolArea), Random.Range(-patrolArea, patrolArea));
    }

If when you press play the enemy doesn’t move increase the moveSpeed. I also changed the Coroutine, WaitForSeconds with a InvokeRepeating Function. If you don’t need it copy only the part with rb.velocity = …