Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by stoniminetar · Oct 01, 2018 at 06:18 AM · touchcamera-movementtouch controlsmultitouch

Multi-touch for camera not working?

Hi, I have a joystick in the Canvas used to move a ball. I want to integrate this camera script: using UnityEngine; using System.Collections;

public class RotateCamera : MonoBehaviour {

 void Start (){
     Vector3 angles= transform.eulerAngles;
     x = angles.y;
     y = angles.x;

     // Make the rigid body not change rotation

     if (GetComponent<Rigidbody>())
         GetComponent<Rigidbody>().freezeRotation = true;
     sensivityX = PlayerPrefs.GetFloat ("camera_sensivity");
     sensivityY = PlayerPrefs.GetFloat ("camera_sensivity") / 1.4f;
     nono = GameObject.Find("VirtualJoystickContainer (1)").GetComponent<RectTransform>();
 }
     
 void FixedUpdate ()
 {
         if (target && GetComponent<Camera> ()) {
             //Zooming with mouse

             distance += Input.GetAxis ("Mouse ScrollWheel") * distance;
             distance = Mathf.Clamp (distance, minDistance, maxDistance);

         if (!RectTransformUtility.RectangleContainsScreenPoint (nono, Input.mousePosition)) {
             if (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Moved) {
                 //One finger touch does orbit
                 touch = Input.GetTouch (0);
                 if (PlayerPrefs.GetInt ("InvertX") == 0)
                     x += touch.deltaPosition.x * xSpeed * 0.02f * sensivityX;
                 else
                     x -= touch.deltaPosition.x * xSpeed * 0.02f * sensivityX;
                 if (PlayerPrefs.GetInt ("InvertY") == 0)
                     y += touch.deltaPosition.y * ySpeed * 0.02f * sensivityY;
                 else
                     y -= touch.deltaPosition.y * ySpeed * 0.02f * sensivityY;
             }

             if (Input.touchCount > 1 && (Input.GetTouch (0).phase == TouchPhase.Moved || Input.GetTouch (1).phase == TouchPhase.Moved)) {
                 //Two finger touch does pinch to zoom
                 var touch1 = Input.GetTouch (0);
                 var touch2 = Input.GetTouch (1);
                 curDist = Vector2.Distance (touch1.position, touch2.position);
                 if (curDist > lastDist) {
                     distance += Vector2.Distance (touch1.deltaPosition, touch2.deltaPosition) * pinchSpeed / 10;
                 } else {
                     distance -= Vector2.Distance (touch1.deltaPosition, touch2.deltaPosition) * pinchSpeed / 10;
                 }
                 lastDist = curDist;
             }
         }
             y = ClampAngle (y, yMinLimit, yMaxLimit);

             Quaternion rotation = Quaternion.Euler (y, x, 0);
             Vector3 vTemp = new Vector3 (0.0f, 0.0f, -distance);
             Vector3 position = rotation * vTemp + target.position;
             transform.position = Vector3.Lerp (transform.position, position, cameraSpeed * Time.deltaTime);
             transform.rotation = rotation;      
         }
 }

 static float ClampAngle(float angle, float min, float max)
 {
     if (angle < -360)
         angle += 360;
     if (angle > 360)
         angle -= 360;
     return Mathf.Clamp (angle, min, max);
 }

The camera itself is working fine but the problem comes when I want to move my ball and move the camera simultaneously. It's like the camera doesn't support multi-touch, I can drag the joystick but the camera is not responding! The camera is moved by moving your finger outside of the joystick to orbit the ball. It even doesn't work when I hold any part of the screen and try to move the camera. I also have another camera script suffering from the same problem. Can this be fixed? I've been struggling with this for a while now.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Oct 01, 2018 at 07:30 AM 0
Share

the script clearly uses one touch for orbiting and two touches for pinching.

avatar image stoniminetar hexagonius · Oct 01, 2018 at 10:20 PM 0
Share

Hi, This script also doesn't work with the joystick. using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Camera$$anonymous$$otor : $$anonymous$$onoBehaviour { private void Start() { offset = new Vector3 (0, yOffset, -1f * distance); }

 private void Update()
 {
         if (Swipe$$anonymous$$anager.Instance.IsSwiping (SwipeDirection.Left))
             SlideCamera (true);
         if (Swipe$$anonymous$$anager.Instance.IsSwiping (SwipeDirection.Right))
             SlideCamera (false);
 }

 private void FixedUpdate()
 {
     desiredPosition = lookAt.position + offset;
     transform.position = Vector3.Lerp (transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
     transform.LookAt (lookAt.position + Vector3.up);
 }

 public void SlideCamera(bool left)
 {
         if (left)
             offset = Quaternion.Euler (0, 60, 0) * offset;
         else
             offset = Quaternion.Euler (0, -60, 0) * offset;
 }

} It only uses one finger swiping. This is the swipe script: using System.Collections; using System.Collections.Generic; using UnityEngine;

public enum SwipeDirection { None = 0, Left = 1, Right = 2, Up = 4, Down = 8, }

public class Swipe$$anonymous$$anager : $$anonymous$$onoBehaviour {

 private void Start()
 {
     instance = this;
 }

 private void Update()
 {
     Direction = SwipeDirection.None;

     if(!RectTransformUtility.RectangleContainsScreenPoint (nono, Input.mousePosition))
     {
     if (Input.Get$$anonymous$$ouseButtonDown (0)) {
         touchPosition = Input.mousePosition;
     }

     if (Input.Get$$anonymous$$ouseButtonUp (0))
     {
         Vector2 deltaSwipe = touchPosition - Input.mousePosition;

         if($$anonymous$$athf.Abs(deltaSwipe.x) > swipeResistanceX)
         {
             // Swipe on the X axis
             Direction |= (deltaSwipe.x <0) ? SwipeDirection.Right : SwipeDirection.Left;
         }

             if ($$anonymous$$athf.Abs (deltaSwipe.y) > swipeResistanceY) {
                 // Swipe on the Y axis
                 Direction |= (deltaSwipe.y < 0) ? SwipeDirection.Up : SwipeDirection.Down;
             }
         }
     }
 }

 public bool IsSwiping(SwipeDirection dir)
 {
     return (Direction & dir) == dir;
 }

}.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

125 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multitouch problem 0 Answers

Multitouch events get stucked. 0 Answers

Help With Multitouch in 2D Windows Store apps 0 Answers

How to get multitouch input using EasyTouch 0 Answers

Simultaneous Multitouch Sends The Touch Over and Over 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges