- Home /
Question by
TomatuAlus · Dec 19, 2016 at 08:40 PM ·
camerarotationmovementjoystick
How to deal with joystick moving and screen swiping colliding?
I have a small sample made for my project, which includes player, camera attached to him and a plane. I have a working joystick, which controls the movement of the player and a swipe screen to rotate the camera view set up (but poorly).
The problem is that when i implemented the camera rotation with screen rotation, now when i use joystick to move around, it also registers as a touch even and the player moves and rotates at the same time.
Should i set a check if the touch isn't t at the x and y region of joystick? Should i put a collider on my joystick?
using UnityEngine;
using CnControls;
public class PlayerMovement : MonoBehaviour {
public GameObject camera;
public GameObject player;
public float speed = 1;
void Start ()
{
}
void Update ()
{
float translationV = CnInputManager.GetAxis("Vertical") * speed;
float translationH = CnInputManager.GetAxis("Horizontal") * speed;
translationV *= Time.deltaTime * speed;
translationH *= Time.deltaTime * speed;
transform.Translate(translationH, 0, translationV);
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
player.transform.Rotate(0,touchDeltaPosition.y,0);
}
}
}
Comment