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 ReticentDaikaiju · Jul 04, 2017 at 04:07 PM · rigidbody2dcollider2dmassbuoyancydensity

Can I make mass and density constant independent of Collider 2D size?

I am currently messing around with 2D buoyancy effectors for a sprite based game. I have made a swimming animation for the player object that changes the size of the collider boundaries frame by frame. It seems as though the buoyancy calculation in Unity finds the density of the object using Rigidbody.mass / Collider2D.size (or something like that). I guess this makes sense for most cases, but because of the animation this constantly changes the density for the player object causing the player to weirdly float or sink with each animation frame. The "real" size of the object should not actually be changing so it would be nice if I could simply tell Unity to use a constant mass and density and just have it ignore the size of the collider. I looked at Rigidbody2D.useAutoMass, but that would change the object's mass with each frame, which is also not what I want. Is there a way to do this, or else a better way to handle buoyancy for an animated object?

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

1 Reply

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

Answer by ReticentDaikaiju · Jul 04, 2017 at 05:41 PM

After some thought I've figured out a simple solution. I can separate the calculated mass/density from the collision detection by simply making two colliders and using one for each task. The way I did this was as follows:

  1. Select useAutoMass in the rigidbody so that I can directly set the density of each collider.

  2. Set the density of the already existing animated collider to 0 so that it does not affect the mass of the rigidbody. This is the collider to be used for the actual collision detection.

  3. Add a second non-animated collider. I can now freely set the size and density of this collider to give me the overall mass and density I want for the rigidbody.

The mass and density is now independent of the size of the animated collider. As long as the non-animated collider is always smaller than the animated collider so that it never actually influences collision detection everything seems to run okay.

Comment
Add comment · 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

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

66 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

Related Questions

How is Rigidbody 2D Auto Mass calculated? 2 Answers

useAutoMass and child objects 1 Answer

Adding Collider2D changed physics on race car.How to compensate for mass loss in the back of the car?or do it some other way. 0 Answers

Calculate objects' mass based on density and volume 1 Answer

Making buoyancy script not mass based 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