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 JaamiParvez · Mar 29, 2016 at 06:40 AM · objectsbouncefalling

How to make object fall slowly but bounce normally?

I have been using Rigidbody drag to slow down my falling object (object falling down with graivity enabled in rigidbody). but using drag effects my objects bounciness too.

So, I am wondering is there any other way to slow down a falling object through which its bounciness is not effected?

This is whats happening with rigidbody.drag set to 4 |(the object is falling slow but it doesn't bounce well): https://media.giphy.com/media/LJJzYn3TYvO4o/giphy.gif

And This is what I want to achieve(only with the bounciness), here rigidbody.drag is set to 1(the object is falling fast and bounces pretty well): https://media.giphy.com/media/xThuWmroOSQjn5nWrm/giphy.gif

Thanks!

Comment
Add comment · Show 1
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 ForeignGod · Mar 29, 2016 at 07:46 AM 0
Share

Have you tried editing physics material so it bounces more?

2 Replies

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

Answer by IrrSoft · Mar 29, 2016 at 12:15 PM

@JaamiParvez As far as I understand the way the physics engine works, the bounciness of the object will depend on the acceleration it has at the moment of impact. If you slow down the way it falls, the force of the impact (and thus the force of the bounce) is smaller too. Right now the first idea I have (and it is very late here, so probably there are more/better ways to do it, but right now I can't think of them) for this would be to :

1 - Make the rigidbody ignore completely the gravity, and calculate/apply it by yourself as a force (controllable with a public float variable so you can regulate how big is the acceleration/how strong is the gravity), then clamp the rigidbody velocity on the y axis (to make sure the object goes at a speed never higher than the one you want). 2 - When the object collides (OnCollisionEnter) multiply the velocity of the impact by X value (bounciness) by the mass of the object and apply it in the direction of the normal of the collision.

This way, you will have separate calculations for the gravity and bounciness, and you will be able to overload the bounciness part, making the bounce stronger than the actual impact.

Basically, you will need to calculate both the gravity and the bounciness by yourself, since the behavior you are aiming for does not follow the standard rules of physics. It can be done, but you will need to provide part of the math by yourself.

Hope it helps!

Comment
Add comment · Show 5 · 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 JaamiParvez · Mar 29, 2016 at 06:51 PM 0
Share

Thanks @IrrSoft , yes for sure it helps!

Im kinda stuck on your point 2:"When the object collides (OnCollisionEnter) multiply the velocity of the impact by X value (bounciness) by the mass of the object and apply it in the direction of the normal of the collision."

I can get the velocity of impact by collision.relativeVelocity.magnitude and multiply it by my bounciness value . but I am not sure "how to apply it in the direction of the normal of the collision?"

See If you can help! Thanks!

avatar image IrrSoft JaamiParvez · Mar 29, 2016 at 07:44 PM 0
Share

@JaamiParvez Basically, the normal of the impact would be the normal of the face where the falling circle collides. In your case, you can use the direction between the centers of both circles and it will give you very similar results (just be sure to normalize that direction). Probably the object will take longer to slow down after the bounce (since the gravity is smaller) but you can play with the different values to get the behavior you are looking for.

https://www.dropbox.com/s/vbpg1l8do6gec5t/bounce.jpg?dl=0

Hope it helps and that you can get it working!

avatar image JaamiParvez · Mar 30, 2016 at 06:18 AM 0
Share

@IrrSoft Thanks again for your time and interest.

This is result Im getting so far, which is pretty much satisfying: https://media.giphy.com/media/dszbomfrVDl84/giphy.gif

and heres the code Im using when balls collide, see if its good or can be better.

  void OnCollisionEnter(Collision collision)
     {
         Vector3 direction;
         direction = this.transform.position + collision.transform.position;
         ContactPoint contact = collision.contacts[0];
         
         rigidbody.velocity = collision.relativeVelocity.magnitude * contact.normal.x * direction.normalized * 10f;
         
     }


Have a Wonderful Day(or Night!) ;)

avatar image IrrSoft JaamiParvez · Mar 30, 2016 at 04:39 PM 0
Share

@JaamiParvez Glad to help and see it worked for the behavior you wanted!

The code you are using seems very efficient, and I dont see any need to make it more simple or change it more if it is already doing what you needed without any expensive calculations, so to me it looks pretty good :)

I just recommend you to run a few more tests just to make sure it will work well for your game :)

EDIT : And if you want to make it work in a more standard-physics way, you can always use contact.normal directly (ins$$anonymous$$d of the normalized direction) and apply collision.relativeVelocity.magnitude*contact.normal * 10f*rigidbody.mass as a Force to the rigidbody, using the AddForce function :)

Have a good day (or night), and good luck with your project!

avatar image JaamiParvez · Mar 30, 2016 at 06:57 PM 0
Share

Thanks Again @IrrSoft!! Appreciate your help!! ;) And I hope too that luck stands by my side through out the entire project! ;)

avatar image
4

Answer by Eno-Khaon · Mar 29, 2016 at 09:03 AM

Is your intent to make the object fall slowly, but otherwise fall in a normal manner (i.e. accelerating at a constant rate) or is the idea to enforce an effective terminal velocity (using drag)?

If it's the former, you can either turn down the global gravity or hijack the physics by implementing your own gravity value for an object, such as turning off an object's gravity and using a line in FixedUpdate() like:

 rigidbody.AddForce(Vector3.down * gravityForce, ForceMode.Acceleration);

If it's the latter, you're missing quite how simple of a drag calculation Unity/PhysX is using. The drag formula is a simple:

 velocity = velocity * (1.0f - (Time.fixedDeltaTime * drag));

What this means in short is that if your drag value is the same as your physics framerate, your object stops moving every frame. With a drag value of 4 and an assumed default physics rate, your object is slowed to:

 velocity *= (1.0f - (0.02f * 4.0f));
 // 8% velocity loss per frame.
 // 50 times per second.

or a terminal velocity of approximately 2.25630 magnitude with the default gravity of -9.81.

Once you hit the ground, then whether the momentum is maintained or not, the drag will have a significantly more noticeable impact on momentum against gravity, so you will barely see it bounce.

Edit: A heavy-handed alternative to enforce a maximum falling speed for an object would be to cap the rigidbody's velocity.

Comment
Add comment · Show 1 · 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 chillersanim · Mar 29, 2016 at 10:44 AM 0
Share

Upvoted for simple alternative to drag and good explanation of what drag actually does.

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

42 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

Related Questions

How to make objects falling down from the top of a scene permanently? 1 Answer

2D ball same bounce height on objects as on the ground 2 Answers

Check Velocity and stop Velocity so Object does not bounce. 0 Answers

Player falling too fast for a collider to stop it 5 Answers

Hey! how to connect two objects? So to make one? 3 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