Adding Swimming and diving to character motor?

Hey working on a player input system to my game I’ve made a huge remake of the motor coming with unity3D, but over all it does the same but adding a few needs i had and fixing the sliding/gravity/jumping problem but one thing it does not add is a swimming/diving script and i’ve been looking a lot around for some way to do the clean and easy… so far a lot of people seems to use triggers that i believe is an okay solution for SWIMMING but yet i haven’t found any thing adding a smooth diving script.

My idea is to maybe allow the character to diving when isswimming = true only, however i find it a little silly to use triggers since there would be MANY places with water… So if there was an easier/other way of doing it i would prefer that. When there is no need to have an “float up” force, however it would be neat to have. An other thing is i would prefer not to use a rigid-body on my characters is possible.

Since diving a flying is almost the same i bet i could use a dive script for flying too maybe???

So resume: What would you add to the character motor to make a smooth swimming and diving option to the character(s)? (and trying avoid using triggers/rigid-body)

My own result and effort so far: I’ve made a class for all the swimming and diving properties but ignoring gravity is mocking me at time and i suddenly fall the the bottom when diving using the triggers…

  • Thanks Jackie

I prefer Trigger Volume, maybe you can try OnTriggerStay(), and don’t make all of the water have trigger volumes, only the water you need to dive and swim, or use tag to seperate them. But as you don’t like it, I’m just saying it.

Another way is force calculate the coordinates, get the CharacterController’s position, height and weight. Then calculate them to check if they are in the water you need to swim/dive.

There gonna be more ways to do it. These are just two I use often.
Good luck.

This tutorial on implementing player swimming might be helpful to you: Click me!

And if you’re curious the full tutorial series can be found here: Click me!

In my opinion making swimming/diving smooth will mostly be an issue of good animation. I think a simple boolean like you suggested would be fine, or using a trigger system in front of your bodies of water would work just as well.