05-17-2023 03:03 AM
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();
}