Search Unity

How can I add collision to prevent player going through wall

Discussion in 'VR' started by Tezelian, Oct 13, 2017.

  1. Tezelian

    Tezelian

    Joined:
    Oct 22, 2013
    Posts:
    256
    Hey guys,

    Just started developing an application for the hololens and so far I managed to get the environment and everything working within the hololens and VS 2015 u3 build.

    Now I am trying to figure out how to create and detect collision so the player or main camera does not go through walls and objects. Like adding a box collider to a cube so the fps controller doesn't go through.

    Do I have to apply spatial mapping renderer and spatial mapping collider in the object I want to add collision to?

    What else do I need to apply, for example, do I add anything to the main camera like a rigid body or box collider?

    Do I treat collisions like I do in normal 3d without hololens?

    Would really appreciate any help and advise

    Kind Regards
     
  2. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    220
    I'm a bit confused about the question, but it sounds like you're asking how to restrict the movement of the player with respect to virtual game objects - if I'm right about that, the answer is, "You can't." The HoloLens reports the position and rotation of the device, and we apply that to the camera - there is no feedback system to make the player hit an imaginary wall.
     
  3. Tezelian

    Tezelian

    Joined:
    Oct 22, 2013
    Posts:
    256
    I've seen
    Hey, I've seen a video of a drone within the hololens hitting an imaginary staircase and stopping

    So basically you're saying in hololens there's no way to create a collision between the player and in-game objects?

    I designed a maze on the hololens and don't want the player or the user using the hololens walking through the walls, so there is no way?

    Is there a way to identify objects within the hololens and maybe say if you are in a certain distance from those walls then rebound or something

    Kind Regards
     
  4. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    220
    The video you mentioned must have had something written into the drone to keep it from hitting virtual walls - or the drone was virtual, not sure, I haven't seen the video you're talking about. The human equivalent would just be telling them not to go through the walls and hoping they don't cheat. I suppose you could just restart the level or something if they do hit a wall.

    Like I said, there is no feedback system to make the player hit an imaginary wall.
     
  5. Tezelian

    Tezelian

    Joined:
    Oct 22, 2013
    Posts:
    256
    Hey sorry for the late reply

    Here is the video



    How can I use spatial mapping within unity to create these collisions and do something when player hits virtual wall

    Do I code the map or the player? So basically if I have a cube in unity, do I attach a script or spatial collision to the ciube or to the player?

    Also is there a way for HoloLens to identify what real life objects are and create collision or something

    Sorry for so many questions as I am new to the HoloLens and want to understand collisions, spatial mapping, etc
     
  6. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    220
    I think there's just a simple misunderstanding here about how spatial mapping and how the colliders work. HoloLens provides a means with which to have virtual objects react to the real world, and not the other way around. So in the video you posted above, that's a virtual drone colliding with a real world wall - that's how collision works with spatial mapping. It basically just boils down to a system where we make a collision mesh out of what the HoloLens reports as a surface, and then the usual Unity physics kick in - that mesh just doesn't have a renderer so you can't see it, but the collision mesh is there.

    You can play around with that by just dropping the SpatialMappingCollider component in your scene (probably on the main camera).

    Kind of confused about your question with the cube. There's no need to apply collision to the player unless you want to respond to when it collides with something, but there's no way to push the player back from when they cross a virtual wall.

    Let me know if you have any more questions.