Detect mouse swipe on 2d object

Hey all,

I am trying to detect a mouse swipe using OverlapPoint on a 2d object that has a circle collider. I’ve spent a lot of time researching the new way to detect overlap points with 2d objects, and this code is working 80% of the time. In my start function for the spawned object I have:

c_collider2d = gameObject.GetComponent<Collider2D>();

My update function looks like this:

void Update() {

	if (!paused) 
	{
		if(Input.GetMouseButtonDown(0))
		{
			mouseIsDown = true;
		}

		if (mouseIsDown)
		{
			Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
			Vector2 mousePos = new Vector2(wp.x, wp.y);

			if (c_collider2d == Physics2D.OverlapPoint(mousePos))
			{
				Debug.Log ("collision *****"); 
				Destroy (this.gameObject);
			}
		}

		if (Input.GetMouseButtonUp (0))
		{
			mouseIsDown = false;
		}

		transform.Rotate (Vector3.forward * rotationValue);
	}
}

Obviously, I am missing something. 80% is great, but that isn’t going to cut it.

Does anyone see what I might be missing? (I’ve tried this with both Collider2D and CircleCollider2d and there is no difference in the ability to detect the overlap point.)

Any assistance is appreciated. Many thanks in advance.

Yeah, I’m convinced. I’m swiping very carefully and the objects are larger and moving at a reasonable speed right now for proof of concept testing. I think it’s a physics issue, as it works almost every time when the object is falling and my mouse is swiping up. Other swipes are not so accurate.

I actually started out with the line creation solution, since I had that already working in a 3d space. I then abandoned it as I kept reading about 2d objects–it seems like the other solutions would be a bit more elegant for the 2d world given some of the newer functions. I’ll try one more fix with this, and then, if it doesn’t work, I’ll go back to my line creation code and see if I can successfully modify it for my sprites. Either way, I’ill post a solution once I have it working.

Thanks for your feedback!