Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to make character swim.

Discussion in 'Scripting' started by PabloEscobarofgames, Dec 15, 2014.

  1. PabloEscobarofgames

    PabloEscobarofgames

    Joined:
    Dec 15, 2014
    Posts:
    22
    Hi

    I'm making a game and it's in the 3D, I have everything finished except the swimming part, the player is a fish and the world/map is underwater of course.

    But I'm so confused, I don't understand how to make the player move around like a fishy does :/ I need to figure it out to finish.

    Thanks guys :)

    Also if you guys are feeling nice, tell me how to apply the movement to a NPC too. Not the AI, I mean the movement. In water you can go up down left right forwards.. LOL you know what i mean.

    Thanks much :)
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,381
    -_-

    Erm, well, underwater is similar to zero gravity in many ways so maybe you can try rigidbodies and uncheck the Gravity option, then go on about applying your animations and movement scripts.
     
  3. BBeck

    BBeck

    Joined:
    Jan 12, 2014
    Posts:
    57
    Underwater physics is totally different than physics in air.

    You have gravity accelerating you downward to the bottom of the ocean at a fixed rate. That's dependent on your weight or mass. And you will sink to the bottom of the ocean based on that alone until you hit bottom and it stops you.

    Counter acting that is buoyancy. Buoyancy pulls you upwards towards the surface. Buoyancy is created by displacing water. If you take a balloon or bladder full of air, the volume of that air will displace an amount of water equal in size. The air weighs less than the water that WOULD have been there. So, you will get an amount of lift equal to the difference between that volume of air and that volume of water. Basically, the amount of weight of water you just replaced with air is going to be a force pushing you to the surface.

    When the two forces are equal, you will float. When they are not, you will either sink or go to the surface.

    Forward movement is an impulse like any impulse in physics. Your velocity or speed is the rate at which you change position per second. An impulse, or acceleration, will push you faster or slower. So, if an acceleration of 3 meters per second is applied to a body at rest it will start to move 3 meters every second in that direction.

    The difference here is that water creates drag where you have no drag in outerspace. So, the water will subtract a certain amount of velocity every second requiring you to constantly accelerate in order to maintain speed. In space, once you accelerate, that speed will be with you for all of eternity. Not so much in water.