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 boxing_rex · Jun 20, 2014 at 06:37 AM · c#2drotationphysicswater

C# Water Rotation

Hello, I am developing a game that replicates water physics (2D Side-View), Everything works fine apart from the fact that once an object(I will call it a brick from now on) starts spinning it will never stop, Here is the part of the code that deals with the floating of the gameObject (It is attached to the water):

 public float waterLevel = 0f;
     public float floatHeight = 2;
     public float bounceDamp = 0.05f;
     public Vector3 buoyancyCentreOffset;
 
     private float forceFactor;
     private Vector3 actionPoint;
     private Vector3 uplift;
 
 
  void OnTriggerStay2D(Collider2D Hit)
     {
         actionPoint = Hit.transform.position + Hit.transform.TransformDirection(buoyancyCentreOffset);
         forceFactor = 1f - ((actionPoint.y - waterLevel) / floatHeight);
         if(forceFactor > 0f){
             uplift = -Physics.gravity * (forceFactor - Hit.rigidbody2D.velocity.y * bounceDamp);
             Hit.rigidbody2D.AddForceAtPosition(uplift, actionPoint);
         }
     }

I was wondering if anyone knew some code that would make the brick rotate towards it original rotation, bearing in mind that it has to look like it would do in real life if the object were to spin in real water.

Thanks for any help in advance.

Comment
Add comment · Show 7
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 hayer · Jun 20, 2014 at 09:00 AM 0
Share

Not really answering your question(hence the comment) but would it be easier to use rigidbody2D.gravityScale = 0.0f to keep the object "floating"? Your also comparing to 0.0f which might not be a good idea. Have you tried comparing with forceFactor > epsilon?

avatar image boxing_rex · Jun 20, 2014 at 02:54 PM 0
Share

The current water based floating system works fine for my purpose as it allows me to control a vast array of variables that I can use to simulate different liquids.

avatar image boxing_rex · Jun 20, 2014 at 02:54 PM 0
Share

It is a good point however, Got any ideas on how to make the rotation happen in water ?

avatar image Bunnybomb7670 · Jun 20, 2014 at 03:12 PM 0
Share

Do you have any damping values set on the rigidbody? if not, it will continue spinning as if it was in space. You may need to adjust damping values on the rigidbody to make it work better?

avatar image boxing_rex · Jun 20, 2014 at 03:47 PM 0
Share

I do not see any damping values on my RigidBody2D

Show more comments

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

24 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

Related Questions

How to rotate a GameObject with another GameObject while simulating gravity? 2 Answers

Flip over an object (smooth transition) 3 Answers

How To Fix My RayCastHit2D in Unity 4.3.4? 0 Answers

2D floating object 2 Answers

How to make a dynamic bow shot and the arrow to curve and turn correctly when shot? 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