- Home /
Question by
lucax · Jul 14, 2014 at 06:11 PM ·
movementtouchdetectioncontinuous
Continuous touch detection problem.
I have a script which moves the player up and down on Y axis. The script seems to have some problem as its not working as I'd wish it would. A) Its either not smooth (the movement is broken) b) Its smooth but I need to take my finger off screen to do second detection ?
void Update()
{
foreach (Touch touch in Input.touches) {
if(touch.phase == TouchPhase.Began)
{
fp = touch.position;
lp = touch.position;
}
if(touch.phase == TouchPhase.Moved)
{
lp = touch.position;
if(lp.y > fp.y)
{
fingerdistMove = lp.y - fp.y;
Debug.Log ("Moved Finger UP " + fingerdistMove);
if(rigidbody.position.y <= upOff){
rigidbody.AddForce (0, myvelocity*4f*fingerdistMove*Time.deltaTime, 0);
}
}
else if(lp.y < fp.y)
{
fingerdistMove = lp.y - fp.y;
Debug.Log ("Moved Finger DOWN " + fingerdistMove);
if(rigidbody.position.y <= downOff){
rigidbody.AddForce (0, (-myvelocity*4f*-fingerdistMove*Time.deltaTime), 0);
}
}
}
}
Now I'll probably get a reply saying take off the Time.deltatime and its already in the physics and change update to fixedUpdate. That is all tried and done and doesn't resolves the main issue. Thanks.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613154037im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with iphone/android touch controls 2 Answers
Touch movement not working 1 Answer
Player not following touch after camera is rotated? 0 Answers
MultiTouch issues 1 Answer
How to make responsive Touch inputs? 1 Answer