Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to make FPS Controller swim underwater?

Discussion in 'Physics' started by avinash_unity542, Nov 5, 2018.

  1. avinash_unity542

    avinash_unity542

    Joined:
    Sep 28, 2018
    Posts:
    13
    Hi I am new to Unity. I have created a basic environment with terrain and water (with underwater effects too). I now want to make the FPS Controller swim using the keys once it gets into the water. I'm a bit stuck here on where should I start. Kindly help.
     
  2. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    559
    let's start with what's your implementation of water.

    is the FPScontroller kinematic or a rigidbody?
     
  3. avinash_unity542

    avinash_unity542

    Joined:
    Sep 28, 2018
    Posts:
    13
    Its a Rigid body. I use the RigidBodyFPSController that comes in the Unity Standard Assets. For water, I use WaterBasicDayTime Prefab.
     
  4. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    559
    so besides the visual it's just a hole, yeah?

    what you need to do is 2 things,

    1) make a force that acts as buoyancy and tries to push the player up to sea level(say y == 0 for example)

    2) override the IsGrounded to detect if in water and if so let the player move "in the air(water)"

    also, i'd bump up the drag a bit to make you move slower in water
     
  5. avinash_unity542

    avinash_unity542

    Joined:
    Sep 28, 2018
    Posts:
    13
    Now I'm able to get an idea of what should be done. Thank you very much. Also, how we shall implement for a normal FPS Controller?. I'm also trying to implement the same for my Oculus Go. I use the OVRPlayerController from Oculus Utilities. I guess its not a Rigid body.