Hi,
I need help on how to make objects in a 2d mode move with a little acceleration to the direction on mouse up.
So basically what I’m trying to do is if I drag the object to the upper right and let go, I want the object to go the same direction (upper right) before dropping (lower right).
Here’s what I have so far. I’m able to hold and drag and let go of the object. The only problem is that when I let go, it drops straight down.
void OnMouseDown() {
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseUp() {
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
rigidbody.velocity = curPosition;
}
void OnMouseDrag() {
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}