• 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
Question by Long2904 · Nov 23, 2019 at 11:59 AM · unity 2drigidbody2dgravityphysics2dconstant

How can you make gravity to not have any acceleration but with const velocity?

So i want my player to fall with const velocity and no acceleration without to disable the rigidbody gravity and apply a const force every frames. I heard that you could achive this by changing the linear drag to some specific number and i also want to know why?

Comment

People who like this

0 Show 0
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
Best Answer

Answer by Bunny83 · Nov 23, 2019 at 01:04 PM

Gravity is a force and therefore applies an acceleration on the object. However in the real world things also do not get infinitely fast when they are "falling" for a long time. Every object has a terminal velocity which is based on the drag form factor of the object, the projected area and the density / viscosity of the fluid the object falls through.


Since simulating real world physics is most the time way too complicated we generally use a simplified physics model. So PhysX / Unity does not have a concept for density, viscosity, form factor or projected area. The drag value of your rigidbody essentially combines all this into a single constant value. Also the drag force in Unity does not depend on the squared velocity but just on the linear velocity.


I've written some helper methods which allows you to calculate the required drag for a given acceleration and wanted terminal velocity. However keep in mind that you do not instantly reach that terminal velocity. In theory you will never reach the terminal velocity since the effective acceleration just gets smaller and smaller over time and you get closer and closer to the terminal velocity.


What you essentially need is the GetDrag and GetDragFromAcceleration methods.

 public static float GetDrag(float aVelocityChange, float aFinalVelocity)
 {
     return aVelocityChange / ((aFinalVelocity + aVelocityChange) * Time.fixedDeltaTime);
 }
 public static float GetDragFromAcceleration(float aAcceleration, float aFinalVelocity)
 {
     return GetDrag(aAcceleration * Time.fixedDeltaTime, aFinalVelocity);
 }

And use it like that once in Start:

 rb.drag = GetDragFromAcceleration(Physics.gravity.magnitude, yourTerminalVelocity);

Or if this creates issues with your jump logic you may want to set / reset it dynamically based on where the player is within the jump cycle. So for example if the velocity.y is positive (jumping up) you set drag to 0 and when falling (velocity.y is negative) you set it to the calculated drag value.

Comment
Long2904
milesizzo
WhisperXD
Bezoro

People who like this

4 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 Long2904 · Nov 23, 2019 at 02:29 PM 0
Share

Thanks for the help. I also want to flip the player's gravity like in vvvvvv so do you think this drag would work well with it?

avatar image WhisperXD · Mar 30, 2020 at 04:03 PM 0
Share

great, u help me a lot !!,,

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

129 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

Related Questions

Change a specific Gameobjects rigidbody gravity to horizontal (left) 1 Answer

Why does poligon collider 2d restricts movement of box collider? 0 Answers

Usegravity for unity2d? 0 Answers

AI phyics movement doesnt work 1 Answer

Simple question about unity 5 rigidbody/gravity 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