• 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
Question by ParisaUnity77 · Oct 19, 2020 at 09:31 AM · touch screengesturesfingergesturetouching

Add limitation in Finger gesture package for touch

Hello everybody,I hope best moment for all of you.I downloaded "(Finger-touch gesture)" package .for"Finger Camera Move 3D Component Script" How can I limit zooming and left and right panning?? I can not understand how can and where Can I add limitation for this Camera?I add some code that I comment my code for limiting for zomming but it does not work, Can you help me where and how can limit moving the target?(Camera) in this code? Thanks

This is main code that can rotate_zoom_pan ect .

// // Fingers Gestures // (c) 2015 Digital Ruby, LLC // http://www.digitalruby.com // Source code may be used for personal or commercial projects. // Source code may NOT be redistributed or sold. //

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

namespace DigitalRubyShared {

 /// <summary>
 /// Allows moving a camera in 3D space using pan, tilt, rotate and zoom mechanics
 /// </summary>
 [AddComponentMenu("Fingers Gestures/Component/Fingers Camera Move 3D", 4)]
 public class FingersCameraMove3DComponentScript : MonoBehaviour
 {
  
     /// <summary>The transform to move, defaults to the transform on this script</summary>
     [Tooltip("The transform to move, defaults to the transform on this script")]
     public Transform Target;

     /// <summary>Controls pan (left/right for strafe, up/down for forward/back) speed in number of world units per screen units panned</summary>
     [Range(-10.0f, 10.0f)]
     [Tooltip("Controls pan (left/right for strafe, up/down for forward/back) speed in number of world units per screen units panned")]
     public float PanSpeed = -1.0f;

     /// <summary>Controls tilt with two finger pan up or down</summary>
     [Range(-10.0f, 10.0f)]
     [Tooltip("Controls tilt with two finger pan up or down")]
     public float TiltSpeed = -1.0f;

     /// <summary>Threshold (in units) tilt gesture must move in order to execute</summary>
     [Tooltip("Threshold (in units) tilt gesture must move in order to execute")]
     public float TiltThreadhold = 0.5f;

     /// <summary>Controls zoom in/out speed</summary>
     [Range(-10.0f, 10.0f)]
     [Tooltip("Controls zoom in/out speed")]
     public float ZoomSpeed = 1.0f;

     /// <summary>Controls rotation speed</summary>
     [Range(-10.0f, 10.0f)]
     [Tooltip("Controls rotation speed")]
     public float RotateSpeed = 1.0f;

     /// <summary>How much to dampen movement, lower values dampen faster</summary>
     [Range(0.0f, 1.0f)]
     [Tooltip("How much to dampen movement, lower values dampen faster")]
     public float Dampening = 0.95f;

     /// <summary>
     /// The pan gesture (left/right)
     /// </summary>
     public PanGestureRecognizer PanGesture { get; private set; }

     /// <summary>
     /// The tilt gesture (up/down)
     /// </summary>
     public PanGestureRecognizer TiltGesture { get; private set; }

     /// <summary>
     /// The scale gesture (zoom in/out)
     /// </summary>
     public ScaleGestureRecognizer ScaleGesture { get; private set; }

     /// <summary>
     /// The rotate gesture (spin in place)
     /// </summary>
     public RotateGestureRecognizer RotateGesture { get; private set; }

     private Vector3 moveVelocity;
     private float tiltVelocity;
     private float angularVelocity;
     private Vector3 zoomVelocity;

     private void PanGestureCallback(GestureRecognizer gesture)
     {
         if (gesture.State == GestureRecognizerState.Executing)
         {
             Quaternion q = Target.rotation;
             q = Quaternion.Euler(0.0f, q.eulerAngles.y, 0.0f);
             moveVelocity += (q * Vector3.right * DeviceInfo.PixelsToUnits(gesture.DeltaX) * Time.deltaTime * PanSpeed * 500.0f);
             moveVelocity += (q * Vector3.forward * DeviceInfo.PixelsToUnits(gesture.DeltaY) * Time.deltaTime * PanSpeed * 500.0f);
         }
     }

     private void TiltGestureCallback(GestureRecognizer gesture)
     {
         if (gesture.State == GestureRecognizerState.Executing)
         {
             tiltVelocity += (DeviceInfo.PixelsToUnits(gesture.DeltaY) * Time.deltaTime * TiltSpeed * 25.0f);
         }
     }

     private void ScaleGestureCallback(GestureRecognizer gesture)
     {
         if (gesture.State == GestureRecognizerState.Executing)
         {
             float zoomSpeed = ScaleGesture.ScaleMultiplierRange;
             **///////My code**
             if (Target.position.z >=-60.0f && Target .position.z<=195.0f)
             {
                 zoomVelocity += (Target.forward * zoomSpeed * Time.deltaTime * ZoomSpeed * 100.0f);

             }
             else if (Target.position.z < -60.0f )
             {
                 Target.position = new Vector3(Target.position.x, Target.position.y, -60.0f);

             }
             else if (Target.position.z > 195.0f)
             {
                 Target.position = new Vector3(Target.position.x, Target.position.y, 195.0f);

             }
             **//end my code**


         }
     }

     private void RotateGestureCallback(GestureRecognizer gesture)
     {
         if (gesture.State == GestureRecognizerState.Executing)
         {
             angularVelocity += (RotateGesture.RotationDegreesDelta * Time.deltaTime * RotateSpeed * 200.0f);
         }
     }

     private void OnEnable()
     {
         if (Target == null)
         {
             Target = transform;
         }

         PanGesture = new PanGestureRecognizer();
         PanGesture.StateUpdated += PanGestureCallback;
         FingersScript.Instance.AddGesture(PanGesture);

         TiltGesture = new PanGestureRecognizer();
         TiltGesture.StateUpdated += TiltGestureCallback;
         TiltGesture.ThresholdUnits = 0.5f; // higher than normal to not interfere with other gestures
         TiltGesture.MinimumNumberOfTouchesToTrack = TiltGesture.MaximumNumberOfTouchesToTrack = 2;
         FingersScript.Instance.AddGesture(TiltGesture);

         ScaleGesture = new ScaleGestureRecognizer();
         ScaleGesture.StateUpdated += ScaleGestureCallback;
         FingersScript.Instance.AddGesture(ScaleGesture);

         RotateGesture = new RotateGestureRecognizer();
         RotateGesture.StateUpdated += RotateGestureCallback;
         FingersScript.Instance.AddGesture(RotateGesture);

         PanGesture.AllowSimultaneousExecution(ScaleGesture);
         PanGesture.AllowSimultaneousExecution(RotateGesture);
         ScaleGesture.AllowSimultaneousExecution(RotateGesture);
     }

     private void OnDisable()
     {
         if (FingersScript.HasInstance)
         {
             FingersScript.Instance.RemoveGesture(PanGesture);
             FingersScript.Instance.RemoveGesture(ScaleGesture);
             FingersScript.Instance.RemoveGesture(RotateGesture);
         }
     }

     private void Update()
     {
        

         TiltGesture.ThresholdUnits = TiltThreadhold;

         Target.Translate(moveVelocity + zoomVelocity, Space.World);
         Target.Rotate(Vector3.up, angularVelocity, Space.World);
         Target.Rotate(Target.right, tiltVelocity, Space.World);

         moveVelocity *= Dampening;
         tiltVelocity *= Dampening;
         zoomVelocity *= Dampening;
         angularVelocity *= Dampening;
     }
 }

}

,

Comment

People who like this

0 Show 0
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

135 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GestureRecognizer ManipulationStarted and ...updated are not working 1 Answer

Swipe gestures: responsiveness vs. stability 0 Answers

Can certain IOS system gestures be disabled in my IOS app? 0 Answers

Finger Gestures mouse click has different transform than game object 1 Answer

How do you make objects stop rotating around the hand when using Magnetic Pinch? 0 Answers


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