- Home /
Question by
erikmokross · Oct 09, 2018 at 01:46 PM ·
c#2dtouch
Object following mouse touch on distance
Hey,
My Code:
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
offset = touchPosition - transform.position;
offset.z = 0;
transform.position = touchPosition + offset;
}
So.. I have the Problem that my object is jumping between the touchPosition. Why and how to fix that?
Comment
Answer by LCStark · Oct 09, 2018 at 02:05 PM
You want to move your object smoothly towards your touch position? You can use Vector3.MoveTowards function to do that.