Unity Editor version: 2022.2.1f1
ML2 OS version: 1.2.0
MLSDK version: 1.2.0
Host OS: (Windows/MacOS) Windows
I'm working on a project that involves interactions based on the ML Controller collision, the collision is happening and the event is invoked on App Sim, but when testing on ML2 nothing is happening (No collision detected.
What could be the reason behind this and how to avoid it as I don't have the ML2 and features must be tested on App Sim first.
Hi @osama.elsharkawyy how are you detecting the collision? Could it be possible that, inside the Magic Leap, the user is moving their hand too quickly for the Unity Physics system to register the collision? How do you have your scene set up?
Detection using built-in physics components, and I don't think that the hand movement speed is causing this in our case.
The scene consist of a UI menu with colliders, in addition to a collider attached to the controller.
I was not able to reproduce this issue. I suspect there might be another script on the controller that is disabling the collider. Or a script that is setting both of the colliders to be triggers.
Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.
The following steps will allow you to detect the trigger enter events:
- Open the Magic Leap Unity Example Project.
- Open the Control scene.
- Add a box collider to the Game Controller object located under the XR rig.
- Enable Is Trigger
- Set the Size to 0.1,0.1,0.1
- Add a Rigidbody to the controller
- Disable Use Gravity and enable Is Kinematic.
- Set the Tag of the Game Controller Object to PlayerHand
- Next create a new Cube in the scene (Create > 3D Object > Cube)
- Set the scale of the cube to 0.1,0.1,0.1 and make sure it is positioned close enough to the camera to be in arms reach
- Create a new script named TriggerColliderExample.
- Add the following lines of code:
using UnityEngine;
using UnityEngine.Events;
public class TriggerColliderExample : MonoBehaviour
{
public UnityEvent OnPress;
public UnityEvent OnRelease;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("PlayerHand"))
OnPress?.Invoke();
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("PlayerHand"))
OnRelease?.Invoke();
}
}
- Add it to the new Cube object.
- In the OnPress, OnRelease events to toggle the visibility of the the UserInterface object by enable and disabling it.
You will now have an scene that detects the collision even in the application and in the app simulator.