I am not sure it’s my code problem or the way I am using it is not correct. But I found the Vector3.SmoothDamp works fine under Update(). Here are my code, anyone can tell me what’s going on?
public class TouchInputSwipeFlick4 : MonoBehaviour
{
public float speed=1.5f;
private float currentObjPosX;
private Vector2 touchDeltaPosition;
public float smoothSpeed=0.1f;
public float smoothTime = 0.3F;
private float goalPos;
void Update ()
{
currentObjPosX = transform.position.x;
goalPos = Mathf.Round(transform.position.x/25)*25;
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
// Get movement of the finger since last frame
touchDeltaPosition = Input.GetTouch(0).deltaPosition;
//P0 to Start Page
if (currentObjPosX>0 && touchDeltaPosition.x>0) GoStart();
//PEnd to Start Page
if (currentObjPosX<-350 && touchDeltaPosition.x<0) GoStart();
// Move object across XY plane by controling the speed, in this case, we are moving the camera
if (currentObjPosX<=0 && currentObjPosX>=-350) //need to be >=-225 otherwise >-225 will let user "stock at that page)
transform.Translate (touchDeltaPosition.x*speed*Time.deltaTime,0,0);
}
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
{
transform.position = Vector3.Lerp(transform.position, new Vector3(goalPos, 0, 0) , Time.time*smoothSpeed);
}
}
Thanks