I have script which I use to move my character along the Y axis with the touch of finger. The problem is I don’t want a secondary effect that comes with it.
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved) {
if((fp.y - myPos.y) < 1)
{
myPos = transform.position;
Touch touch = Input.GetTouch(0);
fp = Camera.main.ScreenToWorldPoint(new Vector2(touch.position.x, touch.position.y));
myPos.y = fp.y;
transform.position = Vector3.Slerp(transform.position,myPos,Time.deltaTime*myvelocity*sFac );
}
//transform.position = new Vector3(myPos.x,
// Mathf.SmoothStep(myPos.y, fp.y, Time.deltaTime*4),0);
}
Alright so the problem is that when I touch anywhere on the screen it instantly transfers player at that Y point. Which is kind of not what I want, I want user to at least click near the Y point of player (not on the player but anywhere on screen) and drag the finger up-down to move the player.
I tried putting up a condition before the Slerp
if((fp.y - myPos.y)<2)
{
//slerp
}
else
{
//nothing
}
but obviously it doesn’t work, someone with more experience on Touch inputs might be able to clear this up. Thanks guys.