Getting a Smooth Movement for Android (Touch To Move - Grid Based)

Well i was looking for some script to attach to my player so when i click over a tile on the gris he automatically walks to.

I got this so far

using UnityEngine;

public class TestTouch : MonoBehaviour
{

    private InputManager inputManager;
    private Camera cameraMain;

    // Start is called before the first frame update
    private void Awake()
    {
        inputManager = InputManager.Instance;
        cameraMain = Camera.main;
    }

    private void OnEnable()
    {
        inputManager.OnStartTouch += Move;
    }

    private void OnDisable()
    {
        inputManager.OnEndTouch -= Move;
    }

    public void Move(Vector2 screenPosition, float time)
    {
        Vector3 screenCoordinates = new Vector3(screenPosition.x, screenPosition.y, cameraMain.nearClipPlane);
        Vector3 worldCoordinates = cameraMain.ScreenToWorldPoint(screenCoordinates);
        worldCoordinates.z = 0;
        transform.position = worldCoordinates;
    }
}

But with this code my player only move to the position where i touch like if teletransport.

By the way im new using Unity and learning to program.

Im looking for when i touch it moves smooth until he reach that point touched.

Any help?

Instead of setting the transform.position directly to the worldCoordinates, which is creating the instant teleportation you’re talking about, store the worldCoordinations as a target destination and inside Update() move the transform.position towards the destination.

Teo im talking of that, you know how can i do that with my Code? Sorry im newbie

You could use this method:

https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html

I will try it and tell you if works. Thanks guys

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

public class ClickToMove : MonoBehaviour
{
    private float speed = 4;
    private InputManager inputManager;
    private Vector3 targetPosition;
    private bool isMoving = false;

    // Update is called once per frame
    void Update()
    {
        if(Input.GetMouseButton(0))
        {
            SetTargetPosition();
        }
        if(isMoving)
        {
            Move();
        }
    }

    void SetTargetPosition()
    {
        targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        targetPosition.z = transform.position.z;

        isMoving = true;
    }

    void Move()
    {
        //transform.rotation = Quaternion.LookRotation(Vector3.forward, targetPosition);
        transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
        if(transform.position == targetPosition)
        {
            isMoving = false;
        }
    }
}

With this im getting the movement that im looking, now i would like to make this movement based on a grid tile with a pathfinding. Any suggestion would be really appreciate.

Lots of tutorials on grid movement, as it is extremely common in games.

Lots of pathfinding tutorials too, such as for Astar.

And lots of tutorials putting those things together.

Hit Youtube.