I'm trying to figure out a work around for a mouse click issue i've run into. I'm using the code below to move game objects around inside OnMouseDrag().
myTransform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 175.0f));
My issue is if I click on corners of the game object the object centers to the mouse and I'm trying to figure out if there is a way to center the click at the center of the game object. It sometimes causes the objects to shoot off in a direction that wasn't intended and its making the game play kind of frustrating.
Any ideas would be appreciated... =)
I will give this a try when I get home... The problem is when I first click the game object right before I drag it... it centers to the mouse but the drag works fine. It just snaps to the center of the mouse sometimes colliding with objects around it that I didn't want it to hit.
– joedrigonI think this should compensate for that
– Atnas1010Ok, cool... I just have one more question am I setting myTransform.position = myTransform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 175.0f)); The mouseOffset variable is kinda throwing me off...
– joedrigonmyTransform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 175.0f))+mouseOffset; And you would ofcourse need to declare private var mouseOffset : Vector3; in the beginning of the script
– Atnas1010This totally did the trick thanks a ton dude!
– joedrigon