How to get the touch controls to work properly?
Hi. I'm working on a game in which the player is supposed to traverse through levels by avoiding and dodging obstacles. I've got it to work properly for the keyboard controls but I just can't get it to work the way I want for mobile controls.
What I want is when the player holds the button to thrust the rocket, it flies up. When the player holds the button to rotate right or left, it rotates accordingly. I'm using the MobileAircraft joystick prefab included in the standard assets.
Here is my code for movement on keyboards:
public void RespondToThrustInput () {
float rotationThisFrame = rcsThrust * Time.deltaTime;
Thrusting (rotationThisFrame);
}
public void Thrusting (float rotationThisFrame) {
if (Input.GetKey (KeyCode.W) )
rigidBody.AddRelativeForce (Vector3.up * rotationThisFrame);
}
public void RespondToRotateInput () {
rigidBody.freezeRotation = true;
float rotationThisFrame = rcsRotate * Time.deltaTime;
if (Input.GetKey (KeyCode.A) )
transform.Rotate(Vector3.forward * rotationThisFrame);
else if (Input.GetKey(KeyCode.D))
transform.Rotate(-Vector3.forward * rotationThisFrame);
rigidBody.freezeRotation = false;
}
So far, if I remove the Input.GetKey for rotation and call it through onclick event or pointer events, it only rotates by tapping the button, not by holding it. Also, when I remove the Input.GetKey for rotation, the rocket automatically starts flying.
Any and all help is appreciated. Thank you in advance.
Your answer
Follow this Question
Related Questions
How do you move 3D object by touch on mobile 0 Answers
Buttons for Player movement 0 Answers
Detect touch gesture in a more than one camera screen rendering 0 Answers
ScreenToWorldPoint on One Axis? 0 Answers
How to separate a Tap from a Swipe? 0 Answers