- Home /
Question by
jovenrp · Feb 15, 2013 at 03:17 AM ·
positioningdragging
How to move an object X or Y axis only
The scenario is if i am touching the object and dragging it up it should only move up and if dragging down should also be moving down. The moving of objects is working but my problem is sometimes even if I am moving my fingers from object to right side it goes upward. -_-" Any help is much appreciated! :D
//INSIDE THE TOUCH PHASE MOVED
if(touch.position.y < lastMousePosition.y){
GameObject.Find("FlipperOne").transform.position.z -= 0.8;
}
if(touch.position.x < lastMousePosition.x){
GameObject.Find("FlipperOne").transform.position.x -= 0.8;
}
lastMousePosition = touch.position;
Comment
Best Answer
Answer by PAEvenson · Feb 15, 2013 at 03:44 AM
I think you need to add a little bit of a threshold for your checks. For example:
float yThreshold = Mathf.Abs(touch.position.y - lastMousePosition.y);
if(touch.position.y < lastMousePosition.y && yThreshold > 0.025f)
{
GameObject.Find("FlipperOne").transform.position.z -= 0.8;
}
Your answer
Follow this Question
Related Questions
Cloud recognition in Vuforia 0 Answers
How can I set the default position of a 3D object? 2 Answers
How to make UI appear in camera scene view? 0 Answers
How to drag mouse on circular arrow 1 Answer