Search Unity

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. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    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. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    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.