Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 EsmeeKhan · Dec 06, 2012 at 08:31 AM · rotationswipegestures

Problem in Rotating Cube on swipe, using FingureGesture Swipes?

Hi !

I am using Cube as a 3D Menu which will have 6 different missions on each side, I have used Fingure Gestures plugin and its works fine in most of the cases e-g tap , drag , move , but in swipe when I get the SwipeDirection.direction it returns a direction which is not a real direction when I test on device e-g if (direction is Up) it should rotate cube in up direction , but moves in left direction which is weird.

I need help in understanding how Fingure Gesture swipe direction can be used to rotate a cube in proper direction where we swipes.

Please look at the following code: You can test it even on just adding these 2 scripts on a UnityCube, but settings its pivot at right direction.This script is used to control the swipes attach this C# script to Cube.

 using UnityEngine;
 using System.Collections;
 
 public class MenuController : MonoBehaviour {
     
     Vector3 heading;
     bool Pinching;
     float fov;
     float minFov = 40f;
     float maxFov = 100f;
     float rotateFrom;
     float rotateTo;
     float sensitivity= 0.02f;
     // variables for cube rotation control
     public Quaternion targetRotation;
     
     void Update()
     {
         
         
     }
     void OnEnable () {
     
         print ("Script is enabled");
         FingerGestures.OnFingerSwipe += FingerGestures_OnFingerSwipe;
         FingerGestures.OnPinchBegin += FingerGestures_OnPinchBegin;
         FingerGestures.OnPinchMove += FingerGestures_OnPinchMove;
         FingerGestures.OnPinchEnd += FingerGestures_OnPinchEnd;
     }
     
     // Convert from screen-space coordinates to world-space coordinates on the Z = 0 plane
     public static Vector3 GetWorldPos( Vector2 screenPos )
     {
         Ray ray = Camera.main.ScreenPointToRay( screenPos );
 
         // we solve for intersection with z = 0 plane
         float t = -ray.origin.z / ray.direction.z;
 
         return ray.GetPoint( t );
     }
     
    void FingerGestures_OnFingerSwipe( int fingerIndex, Vector2 startPos, FingerGestures.SwipeDirection direction, float velocity )
     {
 
         if( direction == FingerGestures.SwipeDirection.Up )
         {
             heading = Vector3.left;
             //heading = Vector3.up;
         }
         
         else if( direction == FingerGestures.SwipeDirection.Down )
         {
             heading = Vector3.right;
             //heading = Vector3.down;
         }
         else if( direction == FingerGestures.SwipeDirection.Right )
         {
             heading = Vector3.down;
             //heading = Vector3.right;
         }
         else if( direction == FingerGestures.SwipeDirection.Left)    
         {
             heading = Vector3.up;
             //heading = Vector3.left;
         }
         this.gameObject.SendMessage("Rotation",heading*90);
         
         print ("Swiped to Direction : "+direction);
         
         
     }
     
      void FingerGestures_OnPinchBegin( Vector2 fingerPos1, Vector2 fingerPos2 )
     {
         Pinching = true;
     }
 
     void FingerGestures_OnPinchMove( Vector2 fingerPos1, Vector2 fingerPos2, float delta )
     {
         if( Pinching)
         {
             // to zoom in/out camera on pinch
             delta *=-(1f);
             fov = Camera.main.fieldOfView;
               fov += delta * sensitivity;
               fov = Mathf.Clamp(fov, minFov, maxFov);
               Camera.main.fieldOfView = fov;
     
         }
     }
 
     void FingerGestures_OnPinchEnd( Vector2 fingerPos1, Vector2 fingerPos2 )
     {
         if(Pinching)
         {
             Pinching= false;
         }
     }
     
     void OnDisable () {
     
         
         print ("Script was removed");
         FingerGestures.OnFingerSwipe -= FingerGestures_OnFingerSwipe;
         FingerGestures.OnPinchBegin -= FingerGestures_OnPinchBegin;
         FingerGestures.OnPinchMove -= FingerGestures_OnPinchMove;
         FingerGestures.OnPinchEnd -= FingerGestures_OnPinchEnd;
         
         
     }
     
 }
 
 

This code is to Rotate Cube in the swipe direction: (place this javascript in standard assets folder and attach this to the Cube) #pragma strict

 enum MoveType {Time, Speed}
 static var use : MoveObject;
 
 //var startRotation;
 
 var startRotation : Vector3;
 var endRotation : Vector3;
 var startTime : float;
 var lerpInterval : float;
 var lerpCalculator : float;
 var isLerping : boolean;
 
 
 function Awake () {
         if (use) {
             Debug.LogWarning("Only one instance of the MoveObject script in a scene is allowed");
             return;
         }
         use = this;
 }
  
 function Translation (thisTransform : Transform, endPos : Vector3, value : float, moveType : MoveType) {
         yield Translation (thisTransform, thisTransform.position, thisTransform.position + endPos, value, moveType);
     }
  
 function Translation (thisTransform : Transform, startPos : Vector3, endPos : Vector3, value : float, moveType : MoveType) {
         var rate = (moveType == MoveType.Time)? 1.0/value : 1.0/Vector3.Distance(startPos, endPos) * value;
         var t = 0.0;
         while (t < 1.0) {
             t += Time.deltaTime * rate;
             thisTransform.position = Vector3.Lerp(startPos, endPos, t);
             yield; 
         }
 }
  
 function Start()
 {
 //    startRotation = this.transform.rotation;
 
 }
 function Rotation (degrees : Vector3) {
 
 
     
     //print("Current Rot: "+ startRotation);
     //var endRotation = this.transform.rotation * Quaternion.Euler(degrees);
     
     
      startRotation = this.transform.localEulerAngles;
      endRotation = (this.transform.localEulerAngles + degrees);
     this.transform.localEulerAngles = endRotation;
     lerpInterval = 1.5f;
     startTime = Time.realtimeSinceStartup;
     isLerping = true;
     
 
     var rate = 1.0/1.5f;
     var t = 0.0;
     while (t < 1.0) {
         t += Time.deltaTime * rate;
         
         //this.transform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
         this.transform.localEulerAngles = Vector3.Lerp(startRotation,endRotation,t);
         yield;    
     }
     
     print("X: " + this.transform.localEulerAngles.x);
     if(this.transform.localEulerAngles.x <0.0f)
     {
         this.transform.localEulerAngles.x=0.0f;
         print("X: " + this.transform.localEulerAngles.x);
     }
     
         print ("Last rotation of Cube: " + endRotation);
         //startRotation = endRotation;
 }
Comment
Add comment
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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

I am having trouble figuring out how to make a swipe gesture. 0 Answers

Swipe Detection Best Practices 1 Answer

Rotate gyroscope-based camera over it's Y axis by swiping 2 Answers

Flip over an object (smooth transition) 3 Answers

How can I achieve this effect? 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