- Home /
Odd touch input problem
As the title says, I'm having an odd reaction when I touch the movement buttons in my game. When I call the movement function with keyboard input, it creates a new Vector3 with the value 1,0,0. When I press down the keyboard button, it smoothly moves the player. However, calling the same function with a touch button causes the player to jump forward a unit, then start moving normally. If I change the new Vector3 to Vector3.right (which has the same value as the Vector3 I created), it works. Here is my code so far :
Touch input example:
this.guiTexture.texture = buttonDown;
touching = true;
PMain.moveDirection = Vector3.right;
PMain.moveDirection *= 3;
Player.transform.localScale = new Vector3 (Player.transform.localScale.x, 1, Player.transform.localScale.z);
if(touching) {
PMain.GetComponent<CharacterController>().SimpleMove(transform.TransformDirection(Vector3.right) * 3);
}
else {
PMain.moveDirection = Vector3.zero;
}
Keyboard Input example:
if(cc.isGrounded) {
if(Input.GetButtonDown("Right")) {
moveDirection = Vector3.right;
moveDirection *= moveSpeed;
this.transform.localScale = new Vector3 (transform.localScale.x, yScale, transform.localScale.z);
}
if(Input.GetButtonDown("Left")) {
moveDirection = Vector3.left;
moveDirection *= moveSpeed;
this.transform.localScale = new Vector3 (transform.localScale.x, -yScale, transform.localScale.z);
moveDirection.y -= gravity * Time.deltaTime;
cc.Move(moveDirection * Time.deltaTime);
The only real difference between the two is that I use simplemove in the touch input, while I use move in keyboard input. I was having problems with move when used with touch input. If anyone could help me, that would be much appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220613121357im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Movement along with touch of finger 2 Answers
Move an object to Input.Touch location 0 Answers
Rotate player to LookAt a touch position 2 Answers
Drag-and-drop dot on mobile 2D 0 Answers
Unity Car Accelerometer 0 Answers