- Home /
Question by
Tofudude624 · Jun 26, 2012 at 12:13 AM ·
iostouch
Moving an object with a touch gesture...
Hello. On an an iOS device, how can I have an object's position mirror that of the touch position? Meaning that if the user starts to slide their finger up, the object will start to move by a certain amount (ex: 100 pixels on the screen is 5 units in world space)? Thanks
Comment
Best Answer
Answer by hathol · Jun 26, 2012 at 12:44 AM
Summarized: Get the delta movement (the movement in between frames), multiply it by a scale factor (.05f in your example) and add that resulting vector to your object position. Something like:
void Update()
{
if(Input.touchCount == 1)
{
//for simultaneous x and y movement
transform.position += Input.touches[0].deltaPosition*scaleFactor;
}
}
Your answer
Follow this Question
Related Questions
Drag an object to touch position(Problem) 1 Answer
iOS multiTouch / release - Strange problem 0 Answers
Make an object move in the direction of touch 0 Answers
Change Player object at touch 1 Answer
Unity double tap explanation -1 Answers