Question by
KingKong320 · Jul 04, 2018 at 04:17 AM ·
touch controlsswipetouchphase
how to drag a 2d object in one direction but even finger is not over the object,either its up or down than opbject but it should be drag in the direction of moveing finger
i am trying to move a 2d object only oin x axis,when i swipe from right to left or left to right it works fine,but when finger is not over the object it stops dragging,i want to keep it drag only in x axis either swipe position is upper or lower than 2d object. How can i achieve this,my code is
if (GetComponent<Collider2D> () == Physics2D.OverlapPoint (touchPos) && moveAllowed) {
dragging = true;
rb.isKinematic = false;
if (transform.name == "hblock(Clone)" || transform.name == "PlayerTile(Clone)" || transform.name == "hblock3(Clone)" || transform.name == "PlayerTilex6(Clone)" || transform.name == "hblock3x6(Clone)" || transform.name == "hblockx6(Clone)") {
rb.MovePosition (new Vector2 (touchPos.x - deltax, transform.position.y));
} else if (transform.name == "vblock(Clone)" || transform.name == "vblock3(Clone)" || transform.name == "vblock3x6(Clone)" || transform.name == "vblockx6(Clone)") {
rb.MovePosition (new Vector2 (transform.position.x, touchPos.y - deltay));
}
}
Comment