public float smoothSpeed;
bool isClicked = false;
Vector2 mousePos;
void Update()
{
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (isClicked == true)
{
transform.position = Vector2.Lerp(transform.position, mousePos, smoothSpeed);
}
}
private void OnMouseDown()
{
isClicked = true;
}
private void OnMouseUp()
{
isClicked = false;
}
Currently, I’m just lerping the position of the game object and the mouse together. But a collision with other game objects is weird because I’m setting position instead of using rigidbody2d. I also want the game object to retain velocity after letting go. Any suggestions?