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
1
Question by Exalia · Nov 11, 2013 at 03:15 PM · rigidbodyvelocitygravitydragconstant force

Horizontal Drag, no Vertical Drag

Hi, I was wondering if it's possible to have different values for the drag of a rigid body, I'm currently moving a character using

 rigidbody.SetVelocity

Using high drag my character doesn't slide around but this means if my character jumps it doesn't fall at free fall speed which I would like.

Doesn't anyone have a solution to this?

Thanks

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
2

Answer by robertbu · Nov 11, 2013 at 03:59 PM

The best solution is to backoff the drag setting and instead keep your objects from moving around by assigning the right physic materials to the colliders.

http://docs.unity3d.com/Documentation/Components/class-PhysicMaterial.html

You might get what you want just by upping the setting for gravity to compensate for the friction. Go to Edit > Project Settings > Physics and set the 'Y' value for gravity to a larger negative number.

Alternately you could play with doing your own drag. Here is a simple version. Set the drag in the Rigidbody back to '0' and then place the following two lines in FixedUpdate():

 rigidbody.velocity.x *= 0.985;
 rigidbody.velocity.z *= 0.985;

If you are writing in C#, you will need to use a temporary variable for this calculation and then assign the result back.

Comment
Add comment · Show 4 · 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 Exalia · Nov 13, 2013 at 11:02 AM 0
Share

Trying out some of these methods now :) Thanks

avatar image Exalia · Nov 13, 2013 at 11:12 AM 0
Share

I'm not sure I fully understand what's going on here with setting the rigidbody velocity to *= 0.985

Could you possibly explain this a little bit?

avatar image robertbu · Nov 13, 2013 at 11:35 AM 1
Share

The line of code expanded out is:

 rigidbody.velocity.x = rigidbody.velocity.x * 0.985;

The '0.985' is just a guess at an appropriate drag setting. You will have to play with this number. The idea is that at each frame, the velocity will decay. So if the x component of the velocity is 2.0, it then would decay to 1.97 and then the following frame it would decay to 1.94 and so on.

avatar image Exalia · Nov 14, 2013 at 10:48 AM 0
Share

Thanks I understand it now, works just like any deceleration, dunno why I couldn't see that before (facepalmed)

I appreciate your help, although eventually I just set x and z velocity to 0 when my analogue sticks magnitude was below a certain threshold XD

I'm not sure if I should mark your comment as answered because I didn't manage to get it to work :| regardless I'll thumb you up for your time :)

Thanks again!

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

16 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

Related Questions

How to get movable/pushable cubes right? 0 Answers

How to set velocity of Rigidbody without changing gravity? 1 Answer

Gravitational pull without losing speed 1 Answer

How to keep gravity when adding velocity to Rigidbody 3 Answers

G Force Acceleration 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