Disabling aiming towards Joystick on first input.
Hello, the intended behavior of this script is that whenever the Joystick is touched and by only one finger in the screen the player cannot change its direction to face it, but if he on the other hand touches anywhere else on the screen, he will be able to aim normally. As such, if there are two fingers on the screen, he will be looking on the direction of the second finger, because the first one is moving the Joystick. I've tried many things now and lost basically two days trying to come up with a solution, any help would be greatly appreciated!
void FixedUpdate()
{
// Makes the player move.
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
// Detects if the player has touched the Joystick.
if(Input.touchCount > 0){
Touch touch = Input.GetTouch(0);
Debug.Log(touch.position);
if(touch.position.x <= 258 && touch.position.y <= 290 && !isMoving){
// Turns the Player Character.
mousePos = cam.ScreenToWorldPoint(touch.position);
TurnPlayer();
// Cooldown for shooting.
if(nextFire > 0){
nextFire -= Time.deltaTime;
return;
}else if (canShoot){
Shoot();
canShoot = false;
}
}
}
// Detects if the player has touched the screen more than once.
if(Input.touchCount > 1){
// Turns the Player Character.
mousePos = cam.ScreenToWorldPoint(Input.GetTouch(1).position);
TurnPlayer();
// Cooldown for shooting.
if(nextFire > 0){
nextFire -= Time.deltaTime;
return;
}else if (canShoot){
Shoot();
canShoot = false;
}
}
Thank you!
Your answer
Follow this Question
Related Questions
OnScreen-Stick that moves to the position touched 0 Answers
How to replace KeyCode.Space with a simple tap on Android? 1 Answer
i want to add touch controlls to my game. how can i do so? *free candy for whoever helps me out* 1 Answer
Touch does not work with the new Input System 5 Answers
iOS touch delay? 0 Answers