I feel like I’m missing something here. I’m currently trying to lerp on touch from current position to my destination. For whatever reason it just does not want to work. I’m trying to replicate the movement of Break Liner by Ketchapp.
Break Liner (Ketchapp) - YouTube
Another idea I had was to use a rigidbody2d and have the player moving up and then lerping to the position but that does not work either. Posting code below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputManager : MonoBehaviour
{
public GameObject player;
public float speed = 1f;
// Use this for initialization
void Start ()
{
player.transform.position = new Vector3(-2, 0, 1);
}
// Update is called once per frame
void Update ()
{
PlayerInput();
player.GetComponent<Rigidbody2D>().velocity = Vector2.up;
}
public void PlayerInput()
{
if(Input.GetMouseButtonDown(0))
{
if(player.transform.position.x == -2)
{
Debug.Log("Pressing");
player.transform.position = Vector3.Lerp(transform.position, new Vector3(2, 0, 1), 1);
}
else if(player.transform.position.x == 2)
{
Debug.Log("Pressing Two");
player.transform.position = Vector3.Lerp(transform.position, new Vector3(-2, 0, 1), 1);
}
}
}
}
To add a little bit more detail: when I change to
player.transform.position = Vector3.Lerp(transform.position, new Vector3(2, 0, 1), Time.deltaTime);
instead of lerping to the new value of 2 on the X, the players nnew position is -43x 20y -4z. What is causing the plays position to be so far off from the new vector I’m giving it?