I’m sorry if already have an answer to this question here, I searched a lot and tried many things.
I just want the object to move smoothly to a specific distance to the right or left when I double click, but it just disappears and appears in the other place. I already tried to use lerp but it didn’t work.
public float laneSpeed;
public float changeSpeed;
private float lastClickTime;
private const float doubleClickTime = 0.2f;
private float h;
private float v;
// Update is called once per frame
void Update()
{
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(h, v, 0);
transform.position += direction * laneSpeed * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.D))
{
float timeSinceLastClick = Time.time - lastClickTime;
if(timeSinceLastClick <= doubleClickTime)
{
transform.position += new Vector3(10, 0, 0); //<----
}
lastClickTime = Time.time;
}
else if (Input.GetKeyDown(KeyCode.A))
{
float timeSinceLastClick = Time.time - lastClickTime;
if (timeSinceLastClick <= doubleClickTime)
{
transform.position += new Vector3(-10, 0, 0); //<----
}
lastClickTime = Time.time;
}
}