TouchScript: Drag Camera Around

Hello

Is it possible to use the TouchScript library to drag (pan) the camera around?

I have been able to successfully pan/drag around a GameObject (cylinder) but no luck getting the main camera to move?

Any suggestions on what TouchScript layers I should use (Fullscreen, Camera, Camera 2d), which GameObject I should I apply the Pan script to and etc. would be extremely helpful. How have you been able to control camera movement using TouchScript?

Here’s my setup but its not moving the camera:

  • MainCamera GameObject has CameraLayer, PanGesture, Transformer2D and BoxCollider components/scripts. Note the camera also has the default camera components.
  • TouchScript GameObject has MobileInput & MouseInput scripts

Inspector Screen Capture: Heres larger image http://answers.unity3d.com/storage/temp/29310-capture.jpg

This question a couple years ago and there are some decent examples that come with the TouchScript asset these days, but I will answer this just in case.

Yes, it is indeed possible to use TouchScript to pan the camera. In the simplest 2D scenario, you add a Main Camera with the following components:

  • Fullscreen Layer with type set to “Main Camera”

  • Screen Transform Gesture with transform type “Translation” checked

  • Camera Controller script (see code snippet below)

       public ScreenTransformGesture PanGesture;
     private Camera myCamera;
     
     private void OnEnable()
     {
         PanGesture.Transformed += Pan;
     }
     
     private void OnDisable()
     {
         PanGesture.Transformed -= Pan;
     }
     
     private void Pan(object sender, System.EventArgs e)
     {
         // Convert touch and camera positions to a common coordinate system.
         var deltaScreenPosition = (Vector2)PanGesture.DeltaPosition;
         var cameraScreenPosition = myCamera.WorldToScreenPoint(myCamera.transform.position);
     
         var newCameraScreenPosition = cameraScreenPosition - deltaScreenPosition
         myCamera.transform.position = myCamera.ScreenToWorldPoint(newCameraScreenPosition);
     }
    

To get TouchScript to work in general, in some other GameObjects have the following components:

  • Event System
  • Touch Script Input Module
  • Touch Manager
  • Standard Input