Hello.
I am trying to make a game on android.
I want to move my object to the tap position and i want there to be a smooth transition from my object to the tap position.
I have the following code but the move it’s made instantly with no smoothing, even with Vector3.Lerp. Can someone help me?
public class MoveToTap : MonoBehaviour {
public float speed;
Vector3 target;
void Update ()
{
if(Input.touchCount > 0 Input.GetTouch(0).phase == TouchPhase.Began) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
if(Physics.Raycast(ray,out hit)) {
if(hit.collider != null) {
target = hit.point;
}
}
}
transform.position = Vector3.Lerp(transform.position, target, Time.deltaTime * speed);
}
}
}