1 2 Previous Next 26 Replies Latest reply on Apr 11, 2017 12:49 PM by supermomo90

    SR300 player gesture controller

    supermomo90

      Hi,

       

      I have made a Unity game which uses box colliders and triggers actions received from the SR300, to control the player (thanks to MartyG), however, I would like to improve the smoothness of this control, such that I do not want to use box colliders but just simple swipes to the left, right, forward and backwards to move the player. May I know how I can do that?

      I have attached my current controller type below.

       

      Thank you

        • 1. Re: SR300 player gesture controller
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi Supermomo90,

          Thank you for contacting us.

          To be honest, any application using Unity Game Engine is out of our support, so we don't have experience with it. Nevertheless, to help you with your project I have found the documentation of Unity, so I hope you find it helpful. (https://docs.unity3d.com/Manual/Physics3DReference.html

          I'm not sure if it is possible to add swipes, but you should look at the documentation to find the way to do this.

          Have a nice day.

          Regards,
          Leonardo R.

          • 2. Re: SR300 player gesture controller
            MartyG

            Apologies for my delay in responding to this message, as I was giving it some thought.  RealSense in Unity can recognise a swipe but only a side swipe, I believe.  Also, it is one of the gestures that RealSense has more trouble recognising than others, causing frustration for the user.  So I personally would not use swipes.

            • 3. Re: SR300 player gesture controller
              MartyG

              I just realised I already built this swipe system in Unity.  Make a copy of the rocker selector mechanism you already built for your menu.  Add trigger blocks on the left and right side too as well as the up and down triggers already there.  Set the selector object's TrackingAction constraints so it can move left and right as well as up and down.  Put scripts in the trigger blocks that make something happen when the selector enters the trigger collider.

              1 of 1 people found this helpful
              • 4. Re: SR300 player gesture controller
                supermomo90

                Hi Leonardo R.,

                 

                Thank you for the document link.

                • 5. Re: SR300 player gesture controller
                  supermomo90

                  Hi MartyG,

                   

                  Thank you for the response. I have made 2 selector objects which control the forward/backwards movement and left/right movements. I have made left hand tracking on 1 selector and a right hand tracking on another selector and have restricted their axes. The controls are working. However, when I use the left hand tracking, the selector which uses right hand tracking seems to move too. May I know if there is a way to prevent the interference? Must I calibrate the SR300?

                   

                  Thank you.

                  • 6. Re: SR300 player gesture controller
                    MartyG

                    Please check the 'Index' number that you have given your TrackingAction in the other selector.  One should have an index of '0' and the other should have an index of '1' so that they can move independently when both hands are being used.  Otherwise, if both selectors are set to '0' then moving one hand will move both of them.

                    1 of 1 people found this helpful
                    • 7. Re: SR300 player gesture controller
                      supermomo90

                      Hi MartyG,

                       

                      Thank you. I have a question. From the GUI built using box Colliders and selectors, is it possible to make the selector go back to origin when the gesture is lost?

                       

                      Thank you.

                      • 8. Re: SR300 player gesture controller
                        MartyG

                        Yes, it is possible.  I built such a reset system myself.  Here is the script that I wrote that is placed inside the object that is to have its position reset. It moves the object smoothly back to the origin point instead of making it snap back instantly (a type of motion called a Lerp).

                         

                        In this line:

                         

                        transform.position = new Vector3 ((Mathf.Lerp (HeightX, 0f, t)), (Mathf.Lerp (HeightY, 0f, t)), (Mathf.Lerp (HeightZ, 0f, t)));

                         

                        change '0' for the X, Y and Z axes to whatever coordinate you want the origin point to be.  So for example, if you wanted it to return to 50,100, 50 then the equation would look like this:

                         

                        transform.position = new Vector3 ((Mathf.Lerp (HeightX, 50f, t)), (Mathf.Lerp (HeightY, 100f, t)), (Mathf.Lerp (HeightZ, 50f, t)));

                         

                        What it is basically doing is saying to look at what the current position of the object is (HeightX, HeightY and HeightZ) and then progressively change the object's position to the target coordinate over the course of 't' seconds of time.

                         

                        At the end of the script, there is an If condition that states that once the script has been activated (made True) then it can only disable once the X coordinate is less than a certain value.  This ensures that the script will not disable until the object has returned to its origin point.  You will need to edit the value in this If instruction for your own project's X origin.  For instance, in my original script my X origin was '0', so I tell the script to stop if its X coordinate becomes < 0.01 (it is easier to trigger an event when near a target instead of absolutely at that target if the coordinates are continually changing during the reset process).

                         

                        To activate the script, set up a SendMessageAction component to trigger 'LateUpdate' when the gesture is lost.

                         

                        Here's the script.

                         

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

                         

                        private float t;

                         

                        private float HeightX;

                        private float HeightY;

                        private float HeightZ;

                         

                        public void LateUpdate ()

                        {

                         

                        this.enabled = true;

                         

                        HeightX = transform.position.x;

                        HeightY = transform.position.y;

                        HeightZ = transform.position.z;

                         

                        t += 0.01f;

                         

                        transform.position = new Vector3 ((Mathf.Lerp (HeightX, 0f, t)), (Mathf.Lerp (HeightY, 0f, t)), (Mathf.Lerp (HeightZ, 0f, t)));

                         

                        if (HeightX < 0.01f) {

                         

                        this.enabled = false;

                         

                        }

                         

                        }

                        }

                        • 9. Re: SR300 player gesture controller
                          supermomo90

                          Hi MartyG,

                           

                          I am supposed to add component in my selector object via the Inspector and then add in the SendMessageAction script. After that, I created a C# file and named it Lerp and added that script to the Selector object too. I also have another script which contains all the trigger actions and I have named it FastSpin. In other words, my Selector object has 3 scripts attached to it as shown in the image attached.

                           

                          May I know where I can add in the 'LateUpdate' trigger component to activate the script?

                           

                          Thank you.

                          Lerp.JPG

                          • 10. Re: SR300 player gesture controller
                            MartyG

                            You would put the word LateUpdate into the 'Function Name' box instead of the word OnTrigger. 

                            • 11. Re: SR300 player gesture controller
                              supermomo90

                              Hi MartyG,

                               

                              Thank you.

                              • 12. Re: SR300 player gesture controller
                                supermomo90

                                Hi MartyG,

                                 

                                I tried to put Hand Index to 1 for one of the selector and 0 for the other selector but the selector with Hand Index = 0 only moves, the selector with hand index = 1 does not move.

                                 

                                Thank you.

                                • 13. Re: SR300 player gesture controller
                                  MartyG

                                  If you are only using one hand, that is how it is supposed to work.  To make the index '1' selector move, you need to put your other hand in front of the camera so that both hands are being used at the same time.  One hand moves the index '0' selector and the other hand moves the index '1' selector.

                                  • 14. Re: SR300 player gesture controller
                                    supermomo90

                                    Hi MartyG,

                                     

                                    Thanks for the reply. I am having some issues with this control. Basically I have created a GUI with left,right,up and down control and would like to use 2 selectors, 1 selector for the up and down and another selector for the left and right. However, I would like to control 1 selector with the right hand and the other with the left hand. But the gesture dont seem to be smooth.

                                     

                                    I would also like to ask if I were to use 1 selector, is there any way I can make the selector to always start from 0,0,0 when the hand is detected? Similar to the Lerp function, but I use Lerp for the end of the gesture. Is there any way to use a similar function to always start the selector from 0,0,0 when the hand is detected?

                                     

                                    Thank you.

                                    1 2 Previous Next