- Home /
How to make object follow touch position?Pls Help
I am trying to make my player follow my touch position only in the x axis. There is a constant force on the y axis(the player moving forward).i want to control the position on the x axis. pls help I found this code but the player only goes up. void Update () { if (Input.touchCount > 0) { // The screen has been touched so store the touch Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
// If the finger is on the screen, move the object smoothly to the touch position
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
transform.position = Vector3.Lerp(transform.position, touchPosition, Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Move object with finger swipe 0 Answers
How to dynamically set transform positions (for a Bezier curve)? 2 Answers
Drag+an+object+to+touch+position(Problem) 0 Answers
Facing the players game object (upward, downward, left, right) on Android phone using joystick 0 Answers
Move with Rigidbody2D in the Z axis 3 Answers