im trying to replace my keyboard code with an android touch system and the result is different.
i want my player move right or left only when touching the screen
this is how my code work for pc keyboard:
in Update:
moveHorizontal = Input.GetAxis ("Horizontal");
movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
in FixedUpdate
player.velocity = movement * speedHorizontal;
-thats above work like a charm! but when i try to set it in touch i dont get the nice smooth movements, because the Update effect the result… here is how i try it in touch:
in Update:
if (Input.touchCount > 0) {
touchPosition = Input.GetTouch (0).position;
if (touchPosition.x > Screen.width / 2) {
moveHorizontal = 1;
if (Input.GetTouch (0).phase == TouchPhase.Ended) {
moveHorizontal = 0f;
}
} else {
moveHorizontal = -1;
if (Input.GetTouch (0).phase == TouchPhase.Ended) {
moveHorizontal = 0f;
}
}
}
movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
in FixedUpdate:
player.velocity = movement * speedHorizontal;
problem is that everything is going fast and not nice and clean as in Input.GetAxis. how i can to simulate Input.GetAxis
thanks for help