Swipe Gesture / Direction / Over an Object

Hello,

I have a few questions for the Unity Masters out there. I am looking at doing a Swipe Gesture over a rigged tree branch that i have rigged up with IK from maya.

First, i have used a touch phase, with Began, moved and ended, but what i wanted to know is how to just have that swipe motion be detected by just the one tree branch because in the end i am going to want to be able to swipe over all three different branches, will i have to do a ray cast from the point of the first touch and if it hits that tree, then just that tree grabs the movement?

Second, I wanted to know if there is a simple way to grab the direction of the Swipe, because i really want it in the end to have the direction of the swipe control the wind (velocity) in the direction of where i touched. Here is a little bit of code that i wrote for the swipe, if anyone could see if its going to work, or if im going in the wrong direction.

thanks

Dan

var Wind : GameObject;
var startPosX = 0;
var endPosX = 0;
var startPosZ = 0;
var endPosZ = 0;
function Update () {

for (var event : iPhoneTouch in iPhoneInput.touches){
		
		if (event.phase == iPhoneTouchPhase.Began){
			startPosX = event.position.x;
			startPosZ = event.position.y;
			//print(startPosX);
		}
		
		if (event.phase == iPhoneTouchPhase.Ended){
			endPosX = event.positionDelta.x;
			endPosZ = -event.positionDelta.y;
			
			//print(startPos + " : " + endPos);
			if(startPosX > 0){
			print ("Negitive Direction");
			rigidbody.velocity.x = -0.2;
			
			if(endPosX > 0){
			print ("Positive Direction");	
			rigidbody.velocity.x = 0.2;
			
			if(startPosZ > 0){
			print ("Positive Direction Z");	
			rigidbody.velocity.z = 0.2;
			
			if(endPosZ > 0){
			print ("Negative Direction Z");	
			rigidbody.velocity.z = 0.2;
			
			
						}
					}
				}	
			}								
		} 
	}
}

The way I would probably do it is by creating a series of explosions on the side the wind is coming from. This will catch any branches with Rigidbody components and move them for you. The reason to make it a series with some variability is to create that illusion of non-constancy of a wind. You find the explanation and an example to get every Rigidbody within the explosion here online:

You can also find it in your own documentation under Rigidbody.

Hi, all,

Would either of you have a solution for a swipe-to-move camera script? I have been searching and experimenting for a while now, but haven’t had much success.

Thanks,

Greg

HI, here is a script I use to detect left and right “swipes” in the upper or bottom part of the Iphone screen (vertical horientation), hope it helps…

var touch1 : float;
var touch2 : float;
var touch3 : float;
var bloccoKO : TouchControllerRag;
var detonatore : Transform;

var regular = 1;
var bloccoSgambetto = 0;

var mov = 0.00;
var touchActive = 0;
function Start() {
	
	regular = 1;
}

function Update () {
	
	

   if (touchActive <1) {
   
   for(touch in iPhoneInput.touches){ 
   
if (regular ==1) {   
	
	
	 	
      if(touch.phase == iPhoneTouchPhase.Began) {
      	touch1 = touch.position.x;
      	touch3 = touch.position.y;
      }
       if(touch.phase == iPhoneTouchPhase.Moved) {
       	touch2 = touch.position.x;
       	if ( touch3 <220) {                      //lower part of the screen
      		
        if (touch2 - touch1 > 70 ) {
      			bloccoSgambetto = 1;
      			bloccoKO.SgambettoDes();
      }
      	if (touch1 - touch2 > 70 ) {
      			bloccoSgambetto = 1;
      			bloccoKO.SgambettoSin();
      }

      	}
if ( touch3 >280) {  //upper part of the screen
if (touch2 - touch1 > 40 ) {
	bloccoKO.SchiaffoDestra();
}
if (touch1 - touch2 > 40 ) {
	bloccoKO.SchiaffoSinistra();
}


}	
       	}
  
	 }
     
      
}
	 
	 
      }

   }
			
}

while copyng and deleting the totally useless parts of my code might have lost some brackets or left to many but the basics of swipes gestures are here…

Thanks, taio84! I appreciate you posting that. I think it will be a good place to start.
Thanks,

Greg

THANK you all so much, i will give this a try tomorrow, and now i see where i was going wrong…

again thanks so much

I just wanted to pipe in and say thanks to taio84 also. This totally helped me as well!

Well, I feel like I’m missing something…

In the above script, what does "var bloccoKO : TouchControllerRag; " refer to? I get an error on this line … Am I missing something?

Thanks for this. It helped a lot!