Search Unity

  1. Unity 2018.3 is now released.
    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. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    15
    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:
    990
    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:
    15
    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:
    990
    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:
    15
    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.