Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Collision detection with Spatial Map

I can't get OnCollisionEnter to fire when my sphere collides with the spatial map while being manipulated.

So I have a sphere that floats (I do not want to apply physics to it). It has a Sphere Collider component on it. I have the following code execute on the object.

    //add a BoxCollider if the interactible does not contain a collider.
    itemCollider = GetComponentInChildren<Collider>() ?? gameObject.AddComponent<BoxCollider>();        
    itemCollider.enabled = true;

    /*
     * add a rigidbody for collision detection. 
     */
    var rigidBody = GetComponentInChildren<Rigidbody>() ?? gameObject.AddComponent<Rigidbody>();
    //we don't want to be at the mercy of physics.
    rigidBody.isKinematic = true;
    rigidBody.detectCollisions = true;
    rigidBody.collisionDetectionMode = CollisionDetectionMode.Continuous;       

The spatial map is composed of game objects on which there is a Mesh Collider. I have added the following code to the SpatialMappingSource.AddSurfaceObject function.

        MeshCollider collider = surface.GetComponent<MeshCollider>();
        collider.enabled = true;   

In a script component of my sphere I have the following function and it never gets called when the sphere hits the spatial map.

void OnCollisionEnter(Collision collision)
{
    System.Diagnostics.Debug.WriteLine("COLLISION!");
}

Is there anyway to detect when the sphere hits the spatial map without applying physics to the sphere?

Best Answers

Answers

  • Could you make the Sphere Collider a trigger instead (isTrigger = true) and then use OnTriggerEnter instead. I don't think the rigidbody would be necessary with this approach.

    void OnTriggerEnter(Collider collider) { System.Diagnostics.Debug.WriteLine("COLLISION!"); }

  • Thanks for the suggestion but no luck.

  • Thanks for the answer. Maybe if I set gravity to 0 or something I can apply physics to the sphere without it falling to the ground.

  • bfichterbfichter
    edited December 2016

    I have come to a similar point in trying to get my "hologram" to collide and stop against spatial map wall or floor. I have looked closely at the Holograms app and it appears that they are using some sort of physics because the hologram will rotate if not aligned and pushed against a wall. But it doesn't appear that they are applying a force as the hologram moves with the gesture. I arrived at the same solution you suggested, but no such luck. Did you ever find a solution that worked?

    Oh, I am not doing gaze placement. I am moving the object with gestures like the Holograms app.

  • @bfichter Did you find a solution of this? I am also looking for some help to achieve similar results.

  • @bfichter @hitesh_sharma Have one of you found a solution? Having the same problem here..

  • @bfichter @AngeloG @hitesh_sharma do you found a solution for the problem. I have an > @bfichter said:

    I have come to a similar point in trying to get my "hologram" to collide and stop against spatial map wall or floor. I have looked closely at the Holograms app and it appears that they are using some sort of physics because the hologram will rotate if not aligned and pushed against a wall. But it doesn't appear that they are applying a force as the hologram moves with the gesture. I arrived at the same solution you suggested, but no such luck. Did you ever find a solution that worked?

    Oh, I am not doing gaze placement. I am moving the object with gestures like the Holograms app.

    Hi @bfichter,
    I'm working on the same problem, did you achieve to fix the problem?

Sign In or Register to comment.