Question by
dylloop · Nov 29, 2018 at 01:09 AM ·
scripting problemmobiletouch controls
How do I stop reading the first touch when using TouchPhase.Moved
I have two scripts one is a player controller with this:
void Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
Touch touch = Input.GetTouch(0);
Ray ray = cam.ScreenPointToRay(touch.position);
RaycastHit hit;
if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
return;
}
if (Physics.Raycast(ray, out hit, 100))
{
Interactable interactable = hit.collider.GetComponent<Interactable>();
if (interactable != null)
{
SetFocus(interactable);
}
else
{
motor.MoveToPoint(hit.point);
RemoveFocus();
}
}
}
}
then my camera script is:
void Update()
{
currentZoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
currentZoom = Mathf.Clamp(currentZoom, minZoom, maxZoom);
currentYaw -= Input.GetAxis("Horizontal") * yawSpeed * Time.deltaTime;
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDirection = Input.GetTouch(0).deltaPosition;
if (touchDirection.x > minSwipe || touchDirection.x < -minSwipe)
{
currentYaw -= touchDirection.x * yawSpeed / mobileYawReduction * Time.deltaTime;
}
}
}
// Update is called once per frame
void LateUpdate () {
transform.position = target.position - offset * currentZoom;
transform.LookAt(target.position + Vector3.up * pitch);
transform.RotateAround(target.position, Vector3.up, currentYaw);
}
Both of these work fine i can move my character with a tap and rotate the camera nicely when swiping the only problem is that when i swipe to rotate it registers the start of the touch and starts moving. how would I avoid this?
Comment