cancel
Showing results for 
Search instead for 
Did you mean: 

Problem: Position constraints of an object with HandTracking (using "OneGrabTranslateTransformer")

Xameal
Honored Guest
(Message a little long to try to explain as well as possible, don't panic, the problem comes down to the question ^^)
I also want to say that if you have another solution to this problem, that is to say another method than mine, I'm interested too. The most important thing is that I can implement what I want. Not necessarily the way I imagine it! Thanks in advance for your answers.
 
Hello,
In a VR application, where the player uses HandTracking. I want to make him take an object in a bag (The bag is hung on a wall to avoid complicating the problem, and it can't be grabbed). 
Picture1.png
Of course, I don't want the object to go through the bag, so I want to force the player to remove the object from the bottom.
For this, I used the script "One Grab Translate Transformer", which allowed me to get the result.
I then added a Cube with a box collider, and the option "Is Trigger" checked, to trigger an event when the object comes in contact with it.
Here, the event resets the values of "One Grab 
Translate Transformer" to 0. To disable the constraints.Picture2.jpg
 
And it works! But unfortunately there is a problem.
 
Of course, after this event, I can move my object in space on the X, Y and Z axes.
But my object does not rotate anymore! Why not?

 

Here is a video of the problem : https://youtu.be/U9RYa2u8lsQ

 

In this video (https://www.youtube.com/watch?v=PU8SQ2Obviw), I saw that using a "Box Collider" can prevent objects from passing through other objects. But this doesn't seem to apply to hand-held objects.
But I'm probably wrong, so maybe there is a simpler solution on this side.

----

Here is a last video using the objects from the official Oculus example scene, and showing what I want to avoid with a box. Since in the end, my problem can be applied to any box, in any situation:
https://youtu.be/WxSXLrMELXw

----

Finally, here is the code:
For the "OneGrabTranslateTransformer" script, I didn't change anything, except adding getters and setters to the constraints:

   public class OneGrabTranslateTransformer : MonoBehaviour, ITransformer
    {
        

        [Serializable]
        public class OneGrabTranslateConstraints
        {
            public bool constraintsAreRelative;
            public FloatConstraint minX;
            public FloatConstraint maxX;
            public FloatConstraint minY;
            public FloatConstraint maxY;
            public FloatConstraint minZ;
            public FloatConstraint maxZ;

            public bool ConstraintsAreRelative { get => constraintsAreRelative; set => constraintsAreRelative = value; }
            public FloatConstraint MinX { get => minX; set => minX = value; }
            public FloatConstraint MaxX { get => maxX; set => maxX = value; }
            public FloatConstraint MinY { get => minY; set => minY = value; }
            public FloatConstraint MaxY { get => maxY; set => maxY = value; }
            public FloatConstraint MinZ { get => minZ; set => minZ = value; }
            public FloatConstraint MaxZ { get => maxZ; set => maxZ = value; }
        } …

----------------

For the "FloatConstraint" script, I added a "resetValue()" function that allows to reset the constraint values to 0:

namespace Oculus.Interaction
{
    [Serializable]
    public class FloatConstraint
    {
        public bool Constrain = false;
        public float Value = 0.0f;


        public void resetValue()
        {
            this.Constrain = false;
            this.Value = 0.0f;
        }
    }
}

---------------

In the Trigger cube script, I simply used the "OnTriggerEnter" function, checking the object tag to avoid triggering the script anyhow:

public class EnterTriggerCagoule : MonoBehaviour
{

    public DisableConstraint disable;
    public string tag = "";
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag(tag))
        {
            disable.disableConstraint();
        }
    }
}

-----------------

Finally, this is what my disableConstraint() function looks like:

public void disableConstraint()
    {
        constraints.MinX.resetValue();
        constraints.MaxX.resetValue();

        constraints.MinY.resetValue();
        constraints.MaxY.resetValue();

        constraints.MinZ.resetValue();
        constraints.MaxZ.resetValue();
    }

 

As you can see, my scripts are not very complicated, and I NEVER touch the rotation values, and I never apply constraints to them. So I am surprised by the problem.
 
Hopefully someone can help me.
Sincerely, Xameal.
0 REPLIES 0