So far I am able to drag my rigidbody2D around the screen using the following code:
void Update() {
if (pickedUp) {
gameObject.rigidbody2D.gravityScale = 0;
screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
Vector3 currentPos = Camera.main.ScreenToWorldPoint (currentScreenPoint);
transform.position = currentPos;
}
}
void OnTouchDrag (Touch touch) {
currentScreenPoint = new Vector3 (touch.position.x, touch.position.y, screenPoint.z);
pickedUp = true;
}
When I release the gameObject, the gravityScale is returned to 2, and drops as its supposed to. But if the user flings the gameObject quickly, I want physics to take over and “lob” the object. Right now, since I am manipulating the transform.position directly, theres no physics taking place. It does not matter how quickly or slowly I move the object, on release it always drops straight down. To my understanding this can be done with rigidbody.MovePosition(). However, since I am using 2D physics, that function does not exist.