News: Enjoy our Christmas offer 30% off on our latest package Tower Defense Level Kit http://u3d.as/m7h

  • October 18, 2018, 02:47:37 AM

Login with username, password and session length

Author Topic: Can't get the grab to work  (Read 9573 times)

Offline maparizeau

  • Newbie
  • *
  • Posts: 7
Can't get the grab to work
« on: April 27, 2013, 04:24:11 AM »
Bonjour ? vous,

Unity v.3.5.7
Sony Xperia Android 2.3.4
Nexus 7 Android 4.2
Easy Touch 2.5

I'm trying to get the drag to work. Unfortunately it only works once every 10 or so tries and no matter how long I touch my gameobject. At first I thought the issue might be with my script or my phone through remote unity. But when I try your scene OneFinger, I have the same issue. No matter how much time I leave my finger on the sphere, it will not move. The problem occurs on my phone and tablet and the camera is Perspective in my scene and orthographic in your example.

When it does work, in my scene, it goes through objects. If I try to detect collision, it will only go up and down. I've tried with and without isKenimatic on my rigidbody. I also tries to make sure that there's only one finger down since I have another script that needs two fingers for the pinch in and out the camera (there's an issue with that to but it's for another post... maybe ;)

Code: [Select]
private Vector3 distance;
    private Vector3 deltaPosition;
    private bool isCollision;

    // Subscribe to events
    private void OnEnable()
    {
        EasyTouch.On_Drag += On_Drag;
        EasyTouch.On_DragStart += On_DragStart;
        EasyTouch.On_DragEnd += On_DragEnd;
    }

    private void OnDisable()
    {
        UnsubscribeEvent();
    }

    private void OnDestroy()
    {
        UnsubscribeEvent();
    }

    private void UnsubscribeEvent()
    {
        EasyTouch.On_Drag -= On_Drag;
        EasyTouch.On_DragStart -= On_DragStart;
        EasyTouch.On_DragEnd -= On_DragEnd;
    }

    // At the drag beginning
    private void On_DragStart(Gesture gesture)
    {
        isCollision = true;

        Debug.Log(string.Format("start Drag {0}", gesture.touchCount.ToString()));
        // Verification that the action on the object
        if(gesture.pickObject == gameObject)
        {
            gameObject.rigidbody.isKinematic = true;
            Vector3 position = gesture.GetTouchToWordlPoint(Camera.main.transform.position.z);
            deltaPosition = position - transform.position;
        }
    }

    // During the drag
    private void On_Drag(Gesture gesture)
    {
        if(!isCollision)
            return;

        Debug.Log(string.Format("dragging {0} - {1}", gesture.touchCount.ToString(), gesture.pickObject.transform.name));

        // Verification that the action on the object
        if(gesture.pickObject == gameObject)
        {
            Vector3 position = gesture.GetTouchToWordlPoint(Camera.main.transform.position.z);
            transform.position = position - deltaPosition;

            Debug.Log(string.Format("moving crate"));
        }
    }

    // At the drag end
    private void On_DragEnd(Gesture gesture)
    {

        // Verification that the action on the object
        if(gesture.pickObject == gameObject)
        {
            gameObject.rigidbody.isKinematic = false;
            Debug.Log(string.Format("drag ended"));
        }
    }


    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log(string.Format("collided : {0}", collision.transform.name));
        isCollision = true;
    }

    private void OnCollisionExit(Collision collision)
    {
        Debug.Log(string.Format("no longer collided : {0}", collision.transform.name));
        isCollision = false;
    }

So any advise would be appreciated :)

Merci,
« Last Edit: April 27, 2013, 04:26:14 AM by maparizeau »

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Can't get the grab to work
« Reply #1 on: April 27, 2013, 11:52:39 AM »
Hi,

You're the first person that raise me this strange issue since the release of 2.5. and I haven't any issue one One Finger example.

I'm going to look at your script, but it's very strange for One Finger Example... I know that I fixing a bug in the 3.0 : - Fix : Now the touch is reset if you start a swipe after a longtap without up your finger

Do you have a skype account ?

Nicolas

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Can't get the grab to work
« Reply #2 on: April 27, 2013, 06:10:26 PM »
Hi,

I made two changes to your script and it works very well for me. Effectively behind the method GetTouchToWordlPoint , there is Camera.ScreenToWorldPoint Unity method where  the Z parameter is related to the camera position.

I will add a parameter in EasyTouch 3.0 to define is Z is relative to camera or world position.

My change :

Quote
       // At the drag beginning
    private void On_DragStart(Gesture gesture)
    {
        isCollision = true;

        Debug.Log(string.Format("start Drag {0}", gesture.touchCount.ToString()));
        // Verification that the action on the object
        if(gesture.pickObject == gameObject)
        {
            gameObject.rigidbody.isKinematic = true;
         //Vector3 position = gesture.GetTouchToWordlPoint(Camera.main.transform.position.z);
            Vector3 position = gesture.GetTouchToWordlPoint(gameObject.transform.position.z-EasyTouch.GetCamera().transform.position.z);
         
              deltaPosition = position - transform.position;
        }
    }

    // During the drag
    private void On_Drag(Gesture gesture)
    {
       if(!isCollision)
            return;

        Debug.Log(string.Format("dragging {0} - {1}", gesture.touchCount.ToString(), gesture.pickObject.transform.name));

        // Verification that the action on the object
        if(gesture.pickObject == gameObject)
        {
         
            //Vector3 position = gesture.GetTouchToWordlPoint(Camera.main.transform.position.z);
         Vector3 position = gesture.GetTouchToWordlPoint(gameObject.transform.position.z-EasyTouch.GetCamera().transform.position.z);
         
         Debug.Log (position);
              transform.position = position - deltaPosition;

            Debug.Log(string.Format("moving crate"));
        }
    }

Nicolas

Offline maparizeau

  • Newbie
  • *
  • Posts: 7
Re: Can't get the grab to work
« Reply #3 on: April 28, 2013, 05:07:56 AM »
Hi Nicolas,

Thanks for the quick reply. I don't have skype by the way.

For your solution
Code: [Select]
gameObject.transform.position.z-EasyTouch.GetCamera().transform.position.z I had to change it to
Code: [Select]
EasyTouch.GetCamera().transform.position.z - gameObject.transform.position.z for the gameobject to follow my finger otherwise, it was going in the opposite direction of my finger.

Merci beaucoup, il ne me reste qu'? figurer comment emp?cher l'instabilit? des mouvements du GameObject lorsqu'une collision est d?tect?. :)

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: Can't get the grab to work
« Reply #4 on: April 28, 2013, 11:28:54 AM »
Hi,

Yes, the meaning of subtraction depends on the orientation of the scene ...

****************************************************************

Tu es francais ?
Oui, le sens de la soustraction d?pend de l'orientation de la scene...

Nicolas

Offline maparizeau

  • Newbie
  • *
  • Posts: 7
Re: Can't get the grab to work
« Reply #5 on: April 30, 2013, 03:06:51 AM »
Merci encore pour l'aide et

oui, je suis canadien fran?ais :)