Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RamboPanda · Jul 04, 2011 at 09:26 PM · waterswim

Make Player Swim in water

Hello. I was wondering whether it is possible to make the player float in water; the player is running on a race track and when the player touches a pool, the player will start to sink and will have to press the up button to float. I was wondering whether it is possible to do that and what kind of script would I have to use. Do I have to use a buoyancy script then link it to my running script? What is recommended to use in this case? Please advise! Thank you in advance! :)

Comment
Add comment · Show 2
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 Chris D · Jul 04, 2011 at 10:37 PM 0
Share

How do you plan to control your character? Are you using the first or third-person controller? Did you create your own movement system?

The answer is yes, you can make a character float on in water, but the method for doing so differs on how you answer the above questions.

avatar image RamboPanda · Jul 05, 2011 at 01:06 AM 0
Share

Hello! I'm planning on using the control buttons on the keypad to move the character; the left/right/up/down and space buttons. I'm using first-person controller. I'm using the script given in the default First Person Controller. Thank you for replying!

This is the movement script that I am using:

 var speed = 6.0;
 var jumpSpeed = 8.0;
 var gravity = 20.0; 
 private var moveDirection = Vector3.zero;
 private var grounded : boolean = false;
 
 function FixedUpdate() 
 {
     if (grounded)
  {
 
 // We are grounded, so recalculate movedirection directly from axes
 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 moveDirection = transform.TransformDirection(moveDirection);
 moveDirection *= speed;
 
         if (Input.GetButton ("Jump")) {
             moveDirection.y = jumpSpeed;
         }
     }
 
     // Apply gravity
     moveDirection.y -= gravity * Time.deltaTime;
     
     // $$anonymous$$ove the controller
     var controller : CharacterController = GetComponent(CharacterController);
     var flags = controller.$$anonymous$$ove(moveDirection * Time.deltaTime);
     grounded = (flags & CollisionFlags.CollidedBelow) != 0;
 }
 
 @script RequireComponent(CharacterController)
 
 function DoSomething()
 {
     
     speed = 6.0;
 
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Chris D · Jul 05, 2011 at 02:49 AM

There is an excellently answered related question here. It's using a modified third-person controller, but the approach is transferable.

That being said, try to break down the components of your problem into the smallest logical pieces. You need to:

  1. detect contact with the water

  2. disable land-type movement and enable water movement

  3. OR add onto land type movement with water movement also

Some things to consider include how or if you want to model buoyancy, how you want the density change of water to affect movement speed (if at all), etc. The easiest way to toggle between the two states is with the OnTriggerStay function.

Comment
Add comment · Show 3 · 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 RamboPanda · Jul 05, 2011 at 03:12 AM 0
Share

Okay thank you so much! I will try it out and ask again if I have any problems. Thank you!

avatar image Chris D · Jul 05, 2011 at 03:15 AM 0
Share

No problem, good luck!

Also, if this has answered your question to your satisfaction, please mark it as accepted (check mark next to thumbs up/down) so people know you found a solution.

avatar image RamboPanda · Jul 05, 2011 at 03:21 AM 0
Share

Okay I will! Thanks!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Swimming/Underwater 3 Answers

How can I fake buoyancy (floating) with a configurable joint (or with a script)? 3 Answers

How to make a lake that you can swim in 2 Answers

Aquarium kinda thingy 1 Answer

I need help with water as a whole 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