How to drag(swipe) object using mouse position?

Once i click on a sphere(GameObject) and drag it to some position, after i release the mouse button it should go to that position in a projectile motion. And i want it using input.mouseposition and not by input.touch.

1 Answer

1

For dragging, I assume this is a 2D game. There are two approaches to dragging: 1) have an object moving itself. You want to take a look at OnMouseDown() and OnMouseDrag() for that approach. Or 2) have an “outside” script moving the object. Take a look at Physics.Raycast(), Input.GetMouseButtonDown(), Input.GetMouseButton(). Both approaches require a translation from pixel coordinates (mouse coordinates) to world coordinates. See Camera.ScreenToWorldPoint() and Camera.ScreenPointToRay() for doing this translation.

As for projectile motion. Search this list for “projectile targeting.” Here is one link:

http://answers.unity3d.com/questions/157390/how-do-i-arc-a-rigidbody-so-it-lands-on-a-target.html

Thanks a lot... it helped a lot