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 eriophora · Aug 15, 2017 at 04:26 AM · collisionphysics

Rigidbody sticks to walls. Or, how the h*ll do you force elastic collisions?

There's at least a dozen posts on this topic, none of which seem to answer anything conclusively. I have four cubes to which I've attached rigidbody2d and box collider 2d components. I have a single sphere, to which I've assigned a rigidbody2d and a circle collider.

If the sphere is moving too slowly when it approaches the wall, any motion perpendicular to the surface is removed and all that remains is motion parallel to the surface.

I really only want to simulate a circle bounding around in a square. Surely this is possible with Unity?

Additional info: Friction and drag are abolished on the all objects in the scene via physics2d materials. There is no drag.

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

2 Replies

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

Answer by eriophora · Aug 16, 2017 at 08:53 PM

It's actually a configurable setting.

In the 2D physics setting, Velocity Threshold dictates the cutoff x where collisions with relative velocity lower than x will be treated as inelastic.

Ultimately, you can't force Unity to treat all collisions as elastic, but by setting Velocity Threshold sufficiently low you can cause nearly all collisions to be treated elastically. If you don't have complex colliders and relatively few colliding bodies, you won't incur a substantial performance hit.

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
avatar image
0

Answer by TheSOULDev · Aug 16, 2017 at 06:03 PM

This is not as trivial as you think it is. You will need to create a function that calculates the new vector on collision. There are plenty of formulae for perfect elastic collisions on the internet (it's classic physics). Using those you can determine a new vector based on your entry vector. Don't think there is anything already implemented in Unity that does this innately, so you'll have to implement it yourself. For a perfectly elastic collision, you will also have to set the mass of the squares to be far larger than the mass of the object you want to bounce off the squares.

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 eriophora · Aug 16, 2017 at 08:57 PM 0
Share

Thanks! As it turns out, Unity treats all sufficiently fast collisions as elastic, and the cutoff is configurable. No doubt this is for efficiency's sake. I just had to set the parameter to a sufficiently small number (see my answer).

Also, a few notes: - There are indeed formulas available, but I suspect that Unity's internal implementation of elastic collisions is more efficient. As in my original post, Unity treats sufficiently fast collisions as elastic so Unity can at least represent that type of interaction. - Since the squares (i.e., the walls) are static, I think their mass is treated as infinitely large already.

Finally, you could argue that implementing fully elastic collisions is more trivial than the system that Unity already has implemented: transitioning from elastic to inelastic collisions as a function of the relative velocity of the objects colliding. While I get why they did it, and I'm glad they've gone ahead and introduced these optimizations "under-the-hood," it'd be nice if it were somehow made more explicit. $$anonymous$$akes me wonder how many other optimizations are lying in wait for me to trip over them.

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

136 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I solve the Box Collider (3D) Edge / Corner Collisions problem? 5 Answers

Rigidbody is behaving abnormally when transformed manually 0 Answers

Character Controller meets Rigidbody 1 Answer

How to get collisions on Character controller? 1 Answer

Rigidbody.MovePosition/MoveRotation Hits far away colliders 2 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