Search Unity

Input.Touches - Simple Gesture Solution

Discussion in 'Assets and Asset Store' started by Song_Tan, Apr 28, 2012.

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @MediaPod34, If I understand you correctly, the build crash as soon as you touch the screen whenever TapDetector is activated in the scene? have you try on other stuff like SwipeDetector or DragDetector? You meantioned that you have been using it for quite a while, is this the first time you test the build on device? Have you try it on other device? Does it work before. If so, have you done any update/change that could have cause this?

    @xgeraldx, sorry I couldnt be much help with the new update. At least it's working now.
     
  2. anpShawn

    anpShawn

    Joined:
    Oct 1, 2012
    Posts:
    18
    Hi songtan- I'm considering buying your input solution but I want to check on something first.
    I'm prototyping a mobile skateboard game that looks like this:
    http://i.imgur.com/sXslabm.jpg

    The game makes use of concurrent touch areas, where the left area controls the player and the right area controls the board. I need to be able to distinguish different inputs in different areas- someone might swipe on the right side but tap on the left side (and also any multi-touches beyond 2 would be ignored)

    Would your system be a good fit for my game? I just wanted to see if it handled this kind of stuff out of the box or if it would need additional work.

    Thanks!
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I wouldn't say it handle the system you need right out of the box. See the way it works is it tells you what gesture has taken place and give you a set a relevant information to the gesture. Those information included touch position. So it's up to you to define the screen into various area (left/right/certain rect on screen), and check against the position of the gesture.

    It's actually much easier than it sound (unless you have a super complex defination of different screen area). There are plenty of examples for that in the demos that comes along with the package. Accept only input that land on certain object, or input that take place on certain area of the screen, etc.

    I would say it's a good fit for your project. However that's just my opinion ofc. I dont see how it can get any simpler without sacrifice the flexibility of design your own screen layout.
     
  4. anpShawn

    anpShawn

    Joined:
    Oct 1, 2012
    Posts:
    18
    Ok, sounds good to me. So I just listen for input events, and those input events come with all of the necessary data? Like I could listen for a swipe event, see where it starts, and go from there.

    However, what about a tap and drag event? Do tap events trigger when the user presses down, releases, or both? For example: letting the user drag a volume slider back and forth on the screen.
     
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes, a for a swipe event, you would be able to know the start position, end position, speed, etc. Same goes for drag but speed is obviously not a applicable for drag. Tap is defined as a sequence where user place a finger on screen and released. That said, you can still detect when a finger is simply pressed down or released using InputTouches. Fyi, you can do that easily with some scripting on your own without any 3rd party library.

    If you want to do handle input to certain UI element like a slider, I would recommend you to use something like NGUI with UI interaction built in. It would be a lot more easier. Not that you cant do that with InputTouches, but it will require some extra coding effort.
     
  6. anpShawn

    anpShawn

    Joined:
    Oct 1, 2012
    Posts:
    18
    So if a user swipes across the screen and lets go, will a swipe AND tap event trigger? sorry for all the questions, just trying to get a good feel for how this will all work
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    To answer your question, no. Swipe and Tap are mutually exclusive. A Tap needs the cursor to stay in the same position where swipe needs the cursor to move. If the position where the finger landed on screen is different than the position where it's being lifted from the screen, it won't be registered as a Tap.
     
  8. anpShawn

    anpShawn

    Joined:
    Oct 1, 2012
    Posts:
    18
    Is there a margin of error? such as if someone taps, moves a pixel, and lets go. Does that make it a swipe?
    Also everything else sounds good, it shouldn't be too hard to do a little extra work and make a contextual system that evaluates a combination of swipes and tap/release states.
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Ofc, each gesture has a set of conditions that define what constitute a valid input and most of them are configurable. For instance, you can specify a minimum threshold of how far the finger should move, how fast it moves before it's considered a swipe event. Or you can set the allowance for finger movement, or even finger on screen duration for tap. Hope that explains things.
     
  10. Sener Dude

    Sener Dude

    Joined:
    Apr 11, 2014
    Posts:
    2
    Hi,

    I purchased your plugin and its really nice. Thank you.

    I have a problem with invoking in OnDragEnd()

    Here is the code:


    Code (CSharp):
    1. void Start () {
    2. progressPerSecond = ((100f / (DamageRainSpell.DamageDuration + 1f)) / 1000f);
    3.  
    4. // If I call from here its working..
    5. // InvokeRepeating("ShowCoolDown", 0, 0.1f);
    6. }
    7. void OnDragEnd()
    8. {
    9. Debug.Log("Start InvokeRepeating");
    10. // If I Invoke in OnDragEnd() its not trigger.
    11. InvokeRepeating("ShowCoolDown", 0, 0.1f);
    12. }
    13.     void ShowCoolDown()
    14.     {
    15.         Debug.Log("Started");
    16.         if (cooldownSprite.fillAmount <= 0)
    17.         {
    18. gameObject.GetComponent<UIDragDropItem>().enabled = true;
    19.             CancelInvoke();
    20.         }
    21.         cooldownSprite.fillAmount -= progressPerSecond;
    22. }
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I've just tried it on my end, work just fine.

    Are you showing me your full code? Your OnDragEnd() doesnt seem right as it should have look like
    Code (csharp):
    1. void OnDragEnd(DragInfo dragInfo)
    Also if this is your full code, you have missing this:
    Code (csharp):
    1.  
    2.   void OnEnable(){
    3.      IT_Gesture.onDraggingEndE += OnDragEnd;
    4.    }
    5.  
    6.    void OnDisable(){
    7.      IT_Gesture.onDraggingEndE -= OnDragEnd;
    8.    }
    9.  
     
  12. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    While optimizing my scene, I am finding that tapping on Unity 2D sprites won't actually return anything, as the ray goes through. Is this supposed to happen?

    Somehow 2D ToolKit sprites work fine and are detected but Unity 2D sprites won't as the ray foes through.

    That's the first problem, which I tried to solve with: Physics2D.Raycast but I am having a bit of trouble passing Vector2 as arguments, or more like I am doing it wrong.

    Any way to solve the ray going through issue would be appreciated.


    Thanks
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    There could be many reason why a raycast fails to pick certain particular things up. Given that you have no problem detecting 2DToolkit sprites, I suspect the problem is your Unity 2Dsprites don't have any collider on them. Unity 2Dsprites doesnt have any collider component by default, you will have to add them manually. Without a collider, no raycast would work. I've just done a quick test myself just to be sure, it works just fine.

    Btw I might be wrong on this but I dont think this is what Physics2D.Raycast are intended for (to detect a collider from cursor position). From what I understand, it's intend for a 2D raycast where z-axis is not considered at all. Hence it takes Vector2 as arguments. Just fyi, you can still use the Vector3 value you obtain from InputTouches to do a 2D raycast, just create a Vector2 variable that uses only x and y value of the cursor position, and use the Vector2 variable as the argument.
     
  14. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    I may be doing something wrong but I don't know what it is then.

    For instance, I do have 2D colliders on both the circle and diamond, but every time I tap on these two the ray goes through. This is not the case with the other shapes though, which are 2DTK.

    Thanks for your help


     

    Attached Files:

  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I doubt it's the 2D collider that causes the issue. You can do a simple test by replacing the 2D collider with a normal box collider and see if that works.

    There might be other reason that could cause the issue, the camera object for instance. Depending on your scene setup (if you have 2 or more camera in the scene), the camera that you are using to form the ray from screen point might not be the camera that are looking at the sprite object. Also, are you using any mask for the raycast?

    Perhaps you can show me your code. It would help me to eliminate the certain possibilties.
     
  16. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    So I removed the 2D collide/2D rigidbody, and instead added a regular rigidbody and sphere collider to the circle unity sprite and it worked.

    So it works fine with a regular collider and with the other 2DTK sprites.

    In my scene I only have one camera, and it is not using masks from the ray cast.

    Here is the script that controls the menu::

    using UnityEngine;
    using System.Collections;
    using Holoville.HOTween;




    public class ShapeMenu : MonoBehaviour
    {
    public ShapesSceneController shapesSceneController;
    public Vector3 positionWhereShapeSpawnsFrom = Vector3.zero;
    public string shapeToSpawn = "";




    public GameObject Square;
    public GameObject Circle;
    public GameObject Diamond;
    public GameObject Heart;
    public GameObject Hexagon;
    public GameObject Oval;
    public GameObject Pentagon;
    public GameObject Star;
    public GameObject Rectangle;
    public GameObject Triangle;




    void OnEnable()
    {
    ITGesture.onMultiTapE += ShapeDetectorFromMenu;
    }

    void OnDisable()
    {
    UnsubscribeEvent();
    }

    void OnDestroy()
    {
    UnsubscribeEvent();
    }

    void UnsubscribeEvent()
    {
    ITGesture.onMultiTapE -= ShapeDetectorFromMenu;
    }




    void Awake ()
    {
    shapesSceneController = GetComponent<ShapesSceneController>();
    // Debug.Log (shapesSceneController);
    }




    public void ShapeDetectorFromMenu(Tap tap)
    {
    RaycastHit hit;
    Ray ray = Camera.main.ScreenPointToRay(tap.pos);




    if (Physics.Raycast(ray, out hit))
    {
    if (hit.collider.gameObject.tag == "ShapeMenu2DSprite")
    {
    shapeToSpawn = hit.collider.gameObject.name;




    SpawnOrigin(shapeToSpawn);
    shapesSceneController.ShapeToSpawn (shapeToSpawn, positionWhereShapeSpawnsFrom);
    shapesSceneController.ShapeResetGeneral ();
    }
    }
    }




    public void SpawnOrigin(string shapeString)
    {
    // Vector3 positionWhereShapeSpawnsFrom = Vector3.zero;
    // MasterAudio.PlaySound ("VoiceOvers", 1f, 1f, 0f, shapeString);




    switch (shapeString)
    {
    case "Square":
    positionWhereShapeSpawnsFrom = new Vector3(Square.transform.position.x, Square.transform.position.y, Square.transform.position.z + 1);
    break;
    case "Circle":
    positionWhereShapeSpawnsFrom = new Vector3(Circle.transform.position.x, Circle.transform.position.y, Circle.transform.position.z + 1);
    break;
    case "Diamond":
    positionWhereShapeSpawnsFrom = new Vector3(Diamond.transform.position.x, Square.transform.position.y, Diamond.transform.position.z + 1);
    break;
    case "Heart":
    positionWhereShapeSpawnsFrom = new Vector3(Heart.transform.position.x, Square.transform.position.y, Square.transform.position.z + 1);
    break;
    case "Hexagon":
    positionWhereShapeSpawnsFrom = new Vector3(Hexagon.transform.position.x, Square.transform.position.y, Hexagon.transform.position.z + 1);
    break;
    case "Oval":
    positionWhereShapeSpawnsFrom = new Vector3(Oval.transform.position.x, Square.transform.position.y, Oval.transform.position.z + 1);
    break;
    case "Pentagon":
    positionWhereShapeSpawnsFrom = new Vector3(Pentagon.transform.position.x, Square.transform.position.y, Pentagon.transform.position.z + 1);
    break;
    case "Star":
    positionWhereShapeSpawnsFrom = new Vector3(Star.transform.position.x, Square.transform.position.y, Star.transform.position.z + 1);
    break;
    case "Rectangle":
    positionWhereShapeSpawnsFrom = new Vector3(Rectangle.transform.position.x, Square.transform.position.y, Rectangle.transform.position.z + 1);
    break;
    case "Triangle":
    positionWhereShapeSpawnsFrom = new Vector3(Triangle.transform.position.x, Square.transform.position.y, Triangle.transform.position.z + 1);
    break;
    }
    }




    public void ShapeMenuSlider()
    {
    if (!shapesSceneController.menuIsHidden)
    {
    HOTween.To (shapesSceneController.buttonMenu.transform, .5f, "position", shapesSceneController.buttonsSlideOut);
    shapesSceneController.menuIsHidden = true;
    MasterAudio.PlaySound("Others", 7f, 1.5f, 0f, "HideShapesMenu");
    }
    else
    {
    HOTween.To (shapesSceneController.buttonMenu.transform, .5f, "position", shapesSceneController.buttonsSlideIn);
    shapesSceneController.menuIsHidden = false;
    MasterAudio.PlaySound("Others", 7f, 1.5f, 0f, "HideShapesMenu");
    }
    }
    }

    Thanks

     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Turns out I was wrong in my earlier post. Just did a little research, so apparently the issue is Physics.Raycast doesnt work with 2D collider. You will need to use Physics2D.Raycast.

    I guess you can either replace your 2D collider with a typical 3D collider, or use Physics2D.Raycast. Something like this:

    Code (csharp):
    1. RaycastHit2D=Physics2D.Raycast(Camera.main.ScreenToWorldPoint(new Vector2(tap.pos.x, tap.pos.y)), Vector2.zero);
    Very sorry about the confusion.
     
  18. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Thanks for confirming what I thought was the problem...

    The solution would need to be applied to these lines but I still haven't been able to figure it out.

    public void LoadMap(Taptap)

    {
    RaycastHit hit;
    Ray ray = Camera.main.ScreenPointToRay(tap.pos);

    if (Physics.Raycast(ray, out hit))
    {
    mapName = hit.collider.gameObject.name;
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry about the earlier example code, it's not the right one as it obviously has some syntax error.

    If you are not sure how. I would recommend you to just stick to replacing the 2D collider with normal collider. The reason is there are many factor to get that line of code working correctly. It depends on your camera placement and projection method. Each projection method will require different input value to the ScreenToWorldPoint function.

    It's quite tricky for me to give you a precise fault proof code as well since I can't test it myself. Fyi, I'm using Unity4.2 so there's no 2D collider.
     
  20. SoftwareLogicAU

    SoftwareLogicAU

    Joined:
    Mar 30, 2014
    Posts:
    34
    Hi, your product is fantastic, but I'm having an issue with swipe detection. The system is intermittently detecting a double swipe where there is only 1. For example, on my game I may swipe left then up (releasing finger in between swipes) and the system is detecting Left Up Up. This is intermittent though, so it's happening randomly in my game.

    I can confirm it's not my code, as I have also wired up detection of the Arrow Keys on the keyboard and it never happens when using these - only when swiping (either by mouse swipe or touch swipe on device).

    I've experimented with all the swipe settings (Max swipe Detection, Min speed etc) but no luck. If I turn on 'Only fire when finger lifted' it often misses my swipe events, so I've had to leave that off. Also, I have disabled 'Enable Multi Swipes' and this had no effect.

    Here is the code which uses the swipe detection (the Debug.Log statement is also showing Left Up Up, so it is receiving it from the SwipeDetector.cs script):

    // Update is called once per frame
    void Update () {
    if (Input.GetKeyDown(KeyCode.LeftArrow)) {
    OrbSpinScript.direction="Left";
    }
    if (Input.GetKeyDown(KeyCode.RightArrow)) {
    OrbSpinScript.direction="Right";
    }
    if (Input.GetKeyDown(KeyCode.UpArrow)) {
    OrbSpinScript.direction="Up";
    }
    if (Input.GetKeyDown(KeyCode.DownArrow)) {
    OrbSpinScript.direction="Down";
    }

    }

    void SwipeActions(SwipeInfo sw){
    if(sw.angle>=45 && sw.angle<135){
    OrbSpinScript.direction="Up";
    }
    else if(sw.angle>=135 && sw.angle<225){
    OrbSpinScript.direction="Left";
    }
    else if(sw.angle>=225 && sw.angle<315){
    OrbSpinScript.direction="Down";
    }
    else{
    OrbSpinScript.direction="Right";
    }
    Debug.Log(OrbSpinScript.direction);
    }

    Have you come across anyone else with this issue and a possible cause/solution?

    Thanks.
     
  21. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Have to say I've never heard of anyone who have the similar issue. Can you let me know what are the setting you are using for your swipe detector. I'm going to do some testing if I can replicate the problem.
     
  22. SoftwareLogicAU

    SoftwareLogicAU

    Joined:
    Mar 30, 2014
    Posts:
    34
    Fantastic - thanks!

    The settings I'm using are:
    Max swipe duration: 1
    Min speed: 0.1
    Min distance: 15
    Max direction change: 35
    Only fire when lift finger: unticked
    Enable Multi swipe: unticked

    I trigger the issue when I do the following type of thing:

    Down Left = OK
    Up Right = OK
    Down Right = OK
    Down Left = Down Left Left!

    But as I said, it's intermittent... If you keep doing it, the problem should happen....

    If you can't reproduce the problem please let me know and I'll try to make a demo project with the issue I can send you.

    Thanks again - great support!
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I tried it a bit. It happened, but not very frequent. Not sure if it's the same with yours.

    From my observation, the problem is that you have the OnlyFireWhenLifeFinger flag unchecked. That allows you to do multiple sequantial swipe without ever lifting the finger. In your case, you might have done a 2 sequential swipe. Perhaps during either the starting or ending phase of the swipe, a very subtle finger movement cause a new swipe. Most likely due to the direction change.

    In short, I would suggest you to increase the MaxDirectionChange value (to something like 50) and check the OnlyFireWhenLifeFinger flag.
     
  24. Sener Dude

    Sener Dude

    Joined:
    Apr 11, 2014
    Posts:
    2

    Ohh you right. I missed to register guesture now its working perfectly. sorry my bad.

    thank you so much!
     
  25. SoftwareLogicAU

    SoftwareLogicAU

    Joined:
    Mar 30, 2014
    Posts:
    34
    Thanks, I tried that but it didn't help. If I check the 'OnlyFireWhenLiftFinger' option, it misses heaps of swipes. The MaxDirectionChange didn't help either.

    Any other suggestions? Thanks.
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm thinking it could be the way you do the swipe which cause most of the swipe input not detected when 'OnlyFireWhenLiftFinger' is checked. The same reason why the double swipe event in a single input sequence.

    There's a much easier solution you can try. That is to put a minimum time between spacing required between 2 swipes. I've got the script modified for purpose. Can you please email me so I can send it to you.
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Perhaps try looking in the documentation? My contact info is there. :)

    Btw, it is k.songtan@gmail.com. Sorry I thought you know.
     
  28. AozakiKyuuji

    AozakiKyuuji

    Joined:
    Sep 21, 2012
    Posts:
    15
    Hi Songtan.

    I'm trying to drag an object but the NGUI camera keeps getting in the way. When I click on "Gizmos" in the Game window, I see two colliders of my object, one from NGUI and the other from main camera.

    Whenever the collider from NGUI disappears off the screen(it's a lot bigger in size), the object cannot be dragged anymore.

    Is there a workaround already? I don't get coding filters as of yet. Any help? Thanks!
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    What exactly are the objects you are trying to drag? Is it a NGUI element? Or just a object in the scene? If it's NGUI element, you should refer to the drag and drop example of NGUI. That's a better way of doing things.

    When I say filter, I actually meant a mask for the raycast. Please refer to this link - http://docs.unity3d.com/Manual/Layers.html. You can add a mask to any raycast you are doing so that it ignores all the ngui element. Something like this:

    Code (csharp):
    1.  
    2.     LayerMask mask=1<<uiLayer;
    3.     Ray ray = Camera.main.ScreenPointToRay(pos);
    4.     RaycastHit hit;
    5.     if(Physics.Raycast(ray, out hit, Mathf.Infinity, ~mask)){
    6.  
    Of course before you do this you have to make sure all the NGUI element are assigned a specific layer.
     
  30. AozakiKyuuji

    AozakiKyuuji

    Joined:
    Sep 21, 2012
    Posts:
    15
    Sorry, I'm trying to drag a game object. Tried the layer mask, it didn't work. I still can't drag it after its collider went off from the NGUI camera :(
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    What do you mean by the "its collider went off"? I would check if the raycast is landed on the intended object. To make thing easier, I would try an empty scene with just the object you want to drag. If you didnt manage to get that working, show me your code, probably something's wrong with it.
     
  32. AozakiKyuuji

    AozakiKyuuji

    Joined:
    Sep 21, 2012
    Posts:
    15
    imma email you. with screenshots. since i'm not sure how to pass an empty scene with NGUI :D
     
  33. cchute

    cchute

    Joined:
    Aug 10, 2014
    Posts:
    30
    Hi I'm having issues using InputTouches with NGUI. You talk about raycasting but I don't really see how that can be integrated into InputTouches.

    Essentially I have a game with NGUI elements on the top of the screen and the main game below. I want the main game to stop receiving InputTouch events when the player is interacting with the NGUI elemetns. Can you post a detailed example of how this is done? Thanks in advance
     
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, you can use a mask to determine if the raycast can only hit object with certain layer. Try check this link. All NGUI object has been assigned a specific layer for the camera culling. As in only the NGUI camera can see the object while the main camera for the game cannot. The same layer assignment can be used for raycast as well so that the raycast only detects NGUI object. So you can have a function like this:

    Code (csharp):
    1.  
    2. bool IsCursorOnNGUIObject(Vector3 mousePosition){
    3.     LayerMask mask=1<<NGUILayer;    //NGUILayer is the layer assigned to all NGUI object
    4.     RaycastHit hit;
    5.     Ray ray = uiCam.ScreenPointToRay(Input.mousePosition);    //uiCam is the NGUI camera
    6.     if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask)){
    7.         //the cursor is on an NGUI-object
    8.         return true;
    9.     }
    10.     return false;
    11. }
    12.  
    Then in your InputTouches function, you can call this function to check if the cursor is landed on an NGUI object, and stop executing the rest of the code if needs be. Like so:

    Code (csharp):
    1.  
    2. void OnTap(TapInfo tap){
    3.     //if the cursor lands on an NGUI object, return
    4.     if(IsCursorOnNGUIObject(tap.pos)) return;
    5.  
    6.     //the rest of the code
    7. }
    8.  
    Hope this help.
     
  35. dabaq

    dabaq

    Joined:
    Apr 20, 2014
    Posts:
    14
    Hi.

    Is it possible to rescrict the drag, so lets say i'm only able to drag a cube on the Y-axis? If so, how can it be done? I'm using playmaker.
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You dont really need to restrict the drag per se. When you move the cube according to the drag, just limit the movement to the Y-axis. I'm not sure why you would do it on PlayMaker since I dont use it myself, but I'll try to explain the logic. When you are relocating the cube according to the drag position, just dont apply any position change in Y and Z-axis. Something like this:

    //intendedPosition being the new position for the cube
    cube.position=new Vector3(cube.position.x, intendedPosition.y, cube.position.z);
     
  37. dabaq

    dabaq

    Joined:
    Apr 20, 2014
    Posts:
    14
    Thanks for your reply.
    Well I'm using playmaker because I suck at coding ;) There is some playmaker actions for input touches.
    Oh okay, so where do I add that code?
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The same logic applies even when you are using PlayMaker, just that you dont need to type that out in syntax. Basically you are just arranging the code in graphical term.

    As to where to add the code, it depends on how your mehanism work in the first place. The line of code I gave you is meant to be an example of how you can restrict movement to only one axis. In practice, you should have some logic sequence that determine when a drag event occur, how to make use of the drag position to move the cube. That line should be at when the new cube position is determined, and we use the cube current position at x and z-axis as the new x and z position, effectively only moving it in y-axis.

    I'm really sorry for not being able to help in term of how to do things in PlayMaker. I'm sure there are resource out there where you can find how to perform certain task/logic-sequence using PlayMaker. I would try the forum.
     
  39. victor-biosphera

    victor-biosphera

    Joined:
    Jun 21, 2010
    Posts:
    67
    Hi Songtan, first of all, thank you for your package, its working well on many of my project...
    Right now im looking for a way to detect when the finger leaves the screen. I mean, when you do not have a finger touching the screen at all.
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    victor-biosphera likes this.
  41. victor-biosphera

    victor-biosphera

    Joined:
    Jun 21, 2010
    Posts:
    67
    so simple! thanks!!!
     
  42. cchute

    cchute

    Joined:
    Aug 10, 2014
    Posts:
    30
    Hello, I am having an issue with InputTouches I sometimes get this crash when making double clicks or longtaps in my game. Here is the message:

    NullReferenceException: Object reference not set to an instance of an object

    TapDetector.CheckMultiTapMouse (Int32 index, Vector2 startPos, Vector2 lastPos) (at Assets/Plugins/InputTouches/TapDetector.cs:112)

    TapDetector+<MouseRoutine>c__IteratorB.MoveNext () (at Assets/Plugins/InputTouches/TapDetector.cs:468)

    ****When clicking error it highlights the second line of this function, line (if(multiTapMouse[index].......)

    void CheckMultiTapMouse(int index, Vector2 startPos, Vector2 lastPos){

    if(multiTapMouse[index].lastTapTime>Time.realtimeSinceStartup-multiTapInterval){

    if(Vector2.Distance(startPos, multiTapMouse[index].lastPos)<multiTapPosSpacing){

    multiTapMouse[index].count+=1;

    multiTapMouse[index].lastPos=startPos;

    multiTapMouse[index].lastTapTime=Time.realtimeSinceStartup;


    IT_Gesture.MultiTap(new Tap(startPos, lastPos, multiTapMouse[index].count, index, true));


    if(multiTapMouse[index].count>=maxMultiTapCount) multiTapMouse[index].count=0;

    }

    else{

    multiTapMouse[index].count=1;

    multiTapMouse[index].lastPos=startPos;

    multiTapMouse[index].lastTapTime=Time.realtimeSinceStartup;


    IT_Gesture.MultiTap(new Tap(startPos, lastPos, 1, index, true));

    }

    }


    Please let me know if this can be resolved it is quite important to our game. Thanks!
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow respond, I'm currently away and unable to look into this. But I shall be returning to normal routine tomorrow evening. I'm sure we can figure out a way to fix the issue.
     
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @cchute, I have took a closer look at the code. Unfortuantely I cant seems to find any fault that could possibly leads to the error you are having. Have you modify the code in anyway? The function that you showed me is a bit different from what I have. Also can you replicate the error in a consistent manner or it's entirely random?

    At any rate, I've pm you a work arround that could possibly fix the issue.
     
  45. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Hi Songtan, love your plugin, helps me a lot in my game.
    I'm trying to use swipe right now and I have some weird problem going on.
    I have a onSwipeEnd event and I'm looking at the direction/angle values coming from the SwipeInfo.
    Whatever parameter I tune in the Swipe Detector script I only get a angle/direction change in the correct swipe direction every other swipe.
    I'll try to explain this better.
    The first swipe and release direction is always in the direction of the previous one.
    The second swipe actually goes where I just swiped.
    If I swipe again and release in the same direction, no problem it goes in the swipe direction, if not it still goes in the previous direction...
    Any idea?
    And I have Fire when lift finger ON, enable multi swipe off.
    I try to adjust max direction change, removed it from your code, anything. Can't get direction/angle to report the right current swiping direction on the first swipe :(
    Any hint would be great.
     
    Last edited: Sep 21, 2014
  46. cchute

    cchute

    Joined:
    Aug 10, 2014
    Posts:
    30
    Hi nope I haven't changed the code, It happens randomly I am not able to replicate it in a consistent manner. Cheers
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @fmarkus, I've just test onSwipeEnd on my end and have no problem what-so-ever with the swipe direction. I would suggest you to open the SwipeDemo example and try it out and see if the same problem happen. If the swipe direction and angle works fine in SwipeDemo, chances are there problem lies in your code. If that's the case you can email/pm me your code so I can have a look and correct it if possible.

    @cchute, that's unfortunate. Please keep an eye out and stick to the temporary solution for the time being. If the error persists and you manage to find a way to replicate the error, please let me know.
     
  48. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Hi my friend! I am happy customer for a while but know I have bumped into something that I don't know how to solve!
    I wanted to make two joysticks that will control my spaceship, and it should work simultaneously. I am not even sure if this is possible with this package (I know it is possible since AngryBots does something similar but probably using unities functionality)

    Basically I have one joystick with controller that is subscirbed like this:

    Code (CSharp):
    1.     void OnEnable()
    2.     {
    3.         IT_Gesture.onDraggingE += OnDrag;
    4.         IT_Gesture.onDraggingEndE += OnDragEnd;
    5.     }
    6.  
    7.     private void OnDisable()
    8.     {
    9.         IT_Gesture.onDraggingE -= OnDrag;
    10.         IT_Gesture.onDraggingEndE -= OnDragEnd;
    11.     }
    in OnDrag I check if position is in the bounds of the collider if it is than I use DragInfo to process input. It works very well
    if there is only one joystick. if i tried to use two (just make a copy of the first one with the same controller but different id to check against rectangle) it doesn't work right, it seems that as far as dragging is concerned it can't differentiate... :( is this possible to make? Thanks! Looking forward to your response.
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, InputTouches does support concurrent multi-finger drag, as it's shown in TapDemo. So if your code and setup is right, you should be able to just duplicate it and make it dual joystick input. It's hard to tell what could be wrong without knowing your code or how "it doesn't work right". It's either you setup is messed up when you make the copy, or your code doesnt take account of the index of the dragInfo instance.

    You can email me your code so I can take a look.
     
  50. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Hey man, thanks! I didn't realize that TapDemo takes into account multi drag, although I was searching for something like that...I checkout the code and it seems to be something that it will work with my setup, I will check it out and and let you know if I get into problem.. :)

    Thanks again, great package!