Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bronchoscopy simulation with FPS: need ideas!

Discussion in 'Editor & General Support' started by Predster, Feb 12, 2008.

  1. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Greetings,

    For a school project, I'm creating a bronchoscopy simulation in Unity and Maya. I'm using the FPS controller to navigate around inside my model of the bronchial tree. However, I'm running into a few problems and I was wondering if anyone had any bright ideas.

    There are bronchial branches on the sides, as well as on the top and bottom of the model (here's a pic: http://www.dkimages.com/discover/previews/769/20011055.JPG), and the player must be able to enter them. Currently, gravity is a problem, as the controller cannot smoothly navigate into the top and bottom branches. If I reduce gravity too much, it's like the controller is floating through space. I'm at my wit's end as to how to program the controller. If I was animating this, I would put it on an invisible track, but I don't think this is feasible in a game engine. Please help!
     
  2. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    I would try this:

    Skip the FPS Controller and use physics to move the 'player' around. Create a gameobject with a rigidbody, spherecollider and parent the camera to that. Setup rigidbody with useGravity=false and freezeRotation=true and a high drag (maybe 5 to 10). The drag will prevent the object from moving too much when there's no input from the user.

    Add this script to the gameObject with the rigidbody and collider;

    Code (csharp):
    1. var f = 10.0;
    2.  
    3. function FixedUpdate () {
    4.     rigidbody.AddRelativeForce (Vector3.forward * Input.GetAxis("Vertical") * f);
    5. }
    f should be set to something that gives a reasonable speed

    Add the MouseLook script from the standard assets. Set MaximumY MinimumY to 360 and -360.

    Now you have a freefloating object that can collide with the environment, be rotated with the mouse in any direction and pushed forward/backwards with the up/down keys.

    Only drawback I can see is that there is no absoulte up anymore. The user can orient the camera in any direction. If you skip the MaximumY and MinimumY step, or set them to values lower than 360 and higher than -360 you should end up with a fixed 'up'

    Hope that helps,

    Patrik
     
  3. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Thank you!!! This might work! I'm not sure if I even really need a fixed up.


    If I need the player to move left/right to choose a branch I could use that same code, but substitute Vector3.right and "horizontal", correct?
     
  4. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Yes, something like that. If you combine it you can allow the player to move left/right + forward/backwards:

    Code (csharp):
    1. vvar f = 10.0;
    2.  
    3. function FixedUpdate () {
    4.    rigidbody.AddRelativeForce ( Vector3( Input.GetAxis("Horizontal") * f, 0, Input.GetAxis("Vertical") * f));
    5. }
    With the free mouse movement the user can simply rotate the camera towards the place he wants to go and move forward, so it should be possible to go into different branches without the left/right movement.

    /Patrik
     
  5. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Thanks! That is the solution I am looking for, I'll try it right now!
     
  6. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145

    You're right! It is working quite well. However, I do get stuck against the walls sometimes, is there something akin the character controller "skin width" that I could do to help this?
     
  7. metervara

    metervara

    Joined:
    Jun 15, 2006
    Posts:
    203
    Hi.

    my guess is that there's some issue with the model you're using for the environment (your bronchial tree). To verify that this is the case, try creating a sphere primitive in your modelling app, flip its normals and try using that as the environment. So, either,

    1. the problem is solved: Look over your model. Is it closed? Are all normals facing the same way? No lamina faces? Is there a specific case that causes you to get stuck? Maybe a sharp edge?

    2. you still get stuck: The physics simulation might need tweaking. Could be the scale of your scene. Could be something else, hard to say if this is the case...
     
  8. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Hmm.. I seem to get stuck on sharp edges, it's probably the model. I'll see what I can do!

    Thanks again!