- Home /
Question by
Mr_Yogs · Mar 23, 2016 at 12:59 PM ·
android2dmovementrigidbody2dtransform.translate
Make an object that moves relative to the touch more natural
Hello, I am trying to make a game where an object is moved horizontally on the screen, and I want that object to be moved relative to finger touch. This is what I got from somewhere around here in the forum:
if (Input.touchCount == 1)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
transform.Translate(touch.deltaPosition.x / Screen.width * velocityConstant, 0.0f, 0.0f);
transform.position = new Vector2(Mathf.Clamp(transform.position.x, leftLimit, rightLimit), transform.position.y);
}
}
Now, it works fine, it does what it's supossed to do, but I noticed that it's so accurate that it feels really stiff. What I would like to do is make it to feel more "natural". Maybe so that it continues sliding for a bit after I stopped moving. I've tried using a rigidbody component and "addforce", but failed by making the object move extremely inconsistently. I would appreciate any help. Thank you :)
Comment