Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jackie0100 · Jul 30, 2012 at 12:46 AM · charactergravitymotorswimming

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by wolventoad · Jul 30, 2012 at 01:04 AM

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.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jackie0100 · Jul 30, 2012 at 01:22 AM 0
Share

Thanks for the answer, im not 100% sure i get what you mean but atm all water should/are planed to be swimable, and i wanna avoid triggers because in my current code it seems to make thing worse, and also if there should be like 100+ water pools adding all component gonna be a hell... i was thinking about if raycast was an option but still no luck for me... Swim$$anonymous$$g is no problem but diving is the bitch in the script...

ps i really appreciate sample codes since that many times start ideas how is should do.

avatar image wolventoad · Jul 30, 2012 at 01:51 AM 0
Share

Hmm, let me guess.

Your swim has no problem. Just need to check which water's depth is fit to dive, right?

avatar image jackie0100 · Jul 30, 2012 at 02:02 AM 0
Share

i guess yes, idk? need to know then i look down (FPS camera) it will dive in that direction you're facing but when you're swim$$anonymous$$g you should only be able to either swim straight one way or dive, and free movement then diving etc.

avatar image wolventoad · Jul 30, 2012 at 02:16 AM 0
Share

Try your current way, Raycast.

Use Raycast to check if this is the water you canDive. You can search the official docs, there should be a magnitude function to check the length of the ray.

if canDive == true, when your character's eulerAngle is lower than a certain limit, you can make him to go under the water and move around. And change isDiving = true;

if isDiving, once you move above the water, change isDiving to false, and return to swim status.

I hope this idea can help you.

avatar image jackie0100 · Jul 30, 2012 at 02:21 AM 0
Share

i'll give it a try, would i still need a trigger for swim or could i do this with a raycast too?

Show more comments
avatar image
1

Answer by murkantilism · Jul 30, 2012 at 03:39 AM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jackie0100 · Jul 30, 2012 at 03:43 AM 0
Share

already watched i wanna avoid doing what he does and swim$$anonymous$$g is the least of my problem its diving that is the main problem

avatar image MachCUBED · Oct 08, 2012 at 01:47 AM 0
Share

I have a diving and surfacing feature at this Unity Answers page, but there's a problem with the character continuing to dive and surface when you let your finger off of a button. However, if you dive, then press the jump/surface button, you can still stabilize yourself in the water and/or surface. It also works vice-versa.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

CharacterMotor Gravity Set 1 Answer

[HELP] Swim/dive script 0 Answers

C# CharacterMotor crashing. What am I doing wrong? 1 Answer

Making a character move automatically in one direction. 2 Answers

Unity4 GetComponent(CharacterMotor) not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges