- Home /
Question by
swagatrajsr47 · Aug 05, 2020 at 04:52 AM ·
touch controlstouchphasetouch screen
touch controls not working properly
I am trying to move my player using touch on my android device but it is not working as I had expected it to. The player is moving towards the left no matter where you touch the screen. It even doesn't matter if you place your 1st touch towards right, it will still move towards left. If anyone can figure out what I am doing wrong please let me know. I have attached the code which I was using to move the player left and right.
if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0);
if (Input.GetTouch(0).phase == TouchPhase.Stationary)
{
double HalfScreen = Screen.width / 2.0;
Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position);
if (touchPos.x > HalfScreen)
{
rb.transform.Translate(Vector2.right * RightForce * Time.deltaTime);
}
else if (touchPos.x < HalfScreen)
{
rb.transform.Translate(Vector2.left * LeftForce * Time.deltaTime);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Touch screen move - android 1 Answer
Wherever you touch, it will trigger animation on touch area 0 Answers
Desktop Multitouch input 0 Answers
Issue with Touch Buttons 1 Answer