Beginner Unity question regarding touch movement on mobile question

I’ve just started learning Unity and had a question regarding movement.

I made a simple mobile game and want to move my character (left, right, up, and down) using my finger.

I’ve been using the following code to move my character across the screen:

void Update()

if (Input.touchCount > 0) {
Touch touch = Input.GetTouch(0);
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
touchPosition.z = 0f;
transform.position = touchPosition;


However, I’ve been running into issues with collisions (as my character passes through things). I was told not to use the transform property for movement (as it acts more like teleporting than movement). I tried a few other options (like adding a Rigidbody and manipulating the physics) but it’s not working out so I’m somewhat stuck.

Can anyone offer some insight into what my next steps should be?


Privacy & Terms