I’m doing a game that if you click on a side nearby an object, this object move to the opposite side of the mouse.
I done a script that do that, the problem is that it not working smotlhy and isn’t moving aways to the opposite side,
I will post my script here, if I change the transform.translate(mouseDelta) to transform.translate(mouseposition)it move smothly but not even to the right side
using UnityEngine;
using System.Collections;
public class MoveBall : MonoBehaviour
{
public Transform sprite;
Vector2 lastMousePosition;
public Vector2 mousePosition;
Vector2 dir = Vector2.zero;
void Start()
{
lastMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
void Update()
{
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mouseDelta = lastMousePosition - mousePosition;
lastMousePosition = mousePosition;
if(Input.GetMouseButton(0) && MouseIn.mouseOver == true)
{
sprite.transform.Translate(mouseDelta);
}
}
}