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 /
  • Help Room /
avatar image
0
Question by DianaLeNeant · Jan 27, 2017 at 09:16 AM · unity 5physics3dwaterfloating

Getting 'bouyancy' on water to work. Help!

Hi! Before I start explaining, I've to say that I've searched everywhere I could, without results. I know this is an old treat, all the object-water-bounce things, but I just can't make it work. I hope you could help me.

I have this:

 Rigidbody go_RB = GetComponent<Rigidbody>();
 actionPoint = transform.position + transform.TransformDirection(transform.position / 2.5f);
 forceFactor = 1f - ((actionPoint.y - water.transform.position.y) / floatHeight) * bounceDamp;
 
 if (forceFactor > 0f)
 {
     uplift = (-Physics.gravity * (forceFactor - go_RB.velocity.y * bounceDamp)) * (go_RB.mass / 2);
     go_RB.AddForceAtPosition(uplift, actionPoint);
 }

As you can see, I've modded it a little to just bounce until the force 'has gone' (alas, I don't know if I'm doing it the right way, but It worked as expected) . Running at OnCollisionStay and TriggerStay, to execute the code depending if the collider is trigger or not, I also check if the collision object is water or not using tags. The water object have a box collider to avoid the object 'got out' the water if it falls too deep in it, in response to a high-place fall or a high-speed entry to water.

Everything works fine... except that it only do on one single object: the player.

I've tried everything I know (that's not much although), adding the script to the water so, using TriggerEnter and exit, lists all the objects ON the water so I can apply physics only to the objects on the water; also, I've tried attaching the script to each floating object in editor, just in case that didn't work as it have to; and also I've tried attaching the script to every object colliding with the water at run-time... but the result is the same: only the player can float on the water.

I've checked if it's a component lack, as to say "God! I've forgotten to attach a rigidbody, how dumb." or if the script it's not really attached, but no, unfortunately not. I've a rigidbody attached to every single object I wanted to float on water. I've attached the necessary colliders, an so on.

The only difference between the player and a single box (the thing I just can't make float) is that it can move with the axis input and has many colliders. As it is a horse and need to have a precise collision in unity 5, I've attached more than one single collider, so the legs, head and body have their own colliders. It worked just fine in movement and physics thing.

What the heck could I be doing wrong with that single box? it just fall deep on the water, no matter how I mod the rigidbody properties or scale.

Pleas help! I'm so tired and annoyed ... Thanks in advance.

Pd. : If someone needs more information, just ask! I'll post every single line of code and explain it if you need, maybe it could help someone else to improve this water-thing.

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

0 Replies

· Add your reply
  • Sort: 

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

163 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 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 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

Object bounces around as if in water 1 Answer

How do I get an object to behave like a balloon? 0 Answers

How to make water flow and take up volume 0 Answers

Getting the error "ullReferenceException: Object reference not set to an instance of an object PlayerCasting.Update () (at Assets/Scripts/PlayerCasting.js:7) on my JavaScript raycasting script 1 Answer

Rotate sphere to the direction of movement 0 Answers


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