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.
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.
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…