Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Chase-Does · May 03, 2016 at 11:02 PM · watereasyswimming

Swimmable water script needed

BEFORE YOU ANSWER PLEASE READ THE FOLLOWING I don't want to do any coding so please just give the code to me. The code should either detect if a charter is in a box which defines water and makes it swimmable or the other way around not using y-axis as a determiner.

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 BTCallahan · May 07, 2016 at 04:47 PM

@Chase Does

Keep in mind that both the swimmer and the liquid object will need colliders attached and that the liquid collider will need to be a trigger.

 public class Swimmer{//attach this to the character
 
 public bool IsInWater;
 
 public float Buoyancy;//I've found that a value of 4 results in perfect buoyancy
 
 RigidBody rigidBod;
 
 void Start(){
 rigidBod = GetComponent<RigidBody>();
 }
 
 void FixedUpdate(){
 
 if(IsInWater){
 rigidBod.AddForce(0f, Buoyancy * -Physics.gravity.y, 0f);

 //using swimming controls
 }else{
 //use normal controls
 }
 }
 
 }
 
 public class Liquid{//attach this to the liquid

 void OnTriggerEnter(Collider other){

 Swimmer swimmer = other.gameObject.GetComponent<Swimmer>();

 if(swimmer != null){

 swimmer.IsInWater = True;
 }
 }

 void OnTriggerExit(Collider other){

 Swimmer swimmer = other.gameObject.GetComponent<Swimmer>();

 if(swimmer != null){

 swimmer.IsInWater = False;
 }
 }

 }
Comment
Add comment · Show 5 · 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 Chase-Does · May 10, 2016 at 06:24 PM 0
Share

So I attach this to my player? Sorry really afraid of having to restart making my character. public class Swimmer{//attach this to the character

avatar image BTCallahan Chase-Does · May 13, 2016 at 02:27 PM 0
Share

@Chase Does Yeah, that should do it. Sorry about not getting back to you until now.

avatar image Frennle · Jan 04, 2017 at 02:55 AM 0
Share

@BTCallahan how do you attach the script to the player and liquid????

avatar image Hellium Frennle · Jan 04, 2017 at 08:57 AM 0
Share

Both classes must inherit from $$anonymous$$onoBehaviour, BTCallahan may have forgotten to add : $$anonymous$$onoBehaviour when declaring the class

avatar image Walker_Studios Hellium · May 24 at 04:05 PM 0
Share

It dosnt work

avatar image
0

Answer by Frennle · Jan 04, 2017 at 08:57 AM

how do you attach the script to the player and liquid????

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 Walker_Studios · 4 days ago 0
Share

You need to go on add component then search new script and then attach your script to this.

avatar image dcmrobin · 4 days ago 0
Share

when it says: public class Swimmer{//attach this to the character you need to add :MonoBehaviour to it, like this:`public class Swimmer : MonoBehaviour{` and then drag the script onto your player object

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

59 People are following this question.

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

Related Questions

How do you make a transparent volume you can go inside 1 Answer

How can I animate Low-poly Water? 1 Answer

Make water hit target 0 Answers

Player animates with keyboard but not virtual joystick 0 Answers

Why won't waterbasicdaytime load textures/materials 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