mercredi 8 février 2017

Draging an object in one line

Vote count: 0

I am trying to make a draging effect. I have a project where u are supposed to pull a bone out of meat. The draging is working, but when i grab the bone i can move it in all directions. What i would like to achieve is that i can only drag it in one direction. On the images below i mean the red line. I tried many things but nothing worked so far. Any help is appreciated.

enter image description here enter image description here

I used these functions for the dragging.

void OnMouseDown()
{
    offset = this.transform.position - Camera.main.ScreenToWorldPoint(new Vector2(transform.position.x, Input.mousePosition.y));
}

void OnMouseDrag()
{
    Vector3 curScreenPoint = new Vector2(transform.position.x, Input.mousePosition.y);
    Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
    transform.position = curPosition;
}

asked 34 secs ago

Let's block ads! (Why?)



Draging an object in one line

Aucun commentaire:

Enregistrer un commentaire