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.
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.