• 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 lerch23 · Jul 06, 2016 at 08:44 PM · velocityphysics2dspeedfrictionspin

Zero friction, zero drag, zero gravity bouncy ball in 2D

I'm working in 2D with essentially just two visible objects: a playfield and a ball.

I've got a top-down rectangular playfield which is surrounded by one EdgeCollider2D forming the walls of the playfield. This EdgeCollider2D uses a Material with Friction = 0, and Bounciness =1. Other than the EdgeCollider2D, the playfield only has the Transform and a Sprite Renderer. No other component.

Then I've got the ball. Aside from the Transform, it has a Rigidbody2D with mass = 1, linear drag = 0, angular drag = 0, gravity scale = 0, Material = Sprites-Default; and a CircleCollider2D using the same Material as the EdgeCollider2D of the playfield, i.e. with Friction = 0, and Bounciness = 1.

Then I've got a script which applies a once-off force to the ball, setting it in motion on the playfield.

Using the once-off force, when I set the ball off such that it hits the walls mostly at 90 degree angles, then it keeps bouncing around without loosing its initial speed. This is what I would expect as I've set all the frictions and drags = 0 and all the bounciness = 1.

However, when I set the ball off such that it hits the walls at small angles (of just a few degrees), then the speed of the ball changes. It sometimes increases, sometimes decreases. At times, it's come to a complete stand still as it kept loosing speed.

Why would it loose speed if I've set all the frictions and drags = 0 and all the bounciness = 1? And what can I do to make the ball and playfield truly zero friction and zero drag, so that no matter what angle it hits the walls it will never gain or loose its initial speed, which it reached by applying the initial once-off force?

I had the hunch there there might be some rotational force or spin at play, however, I cannot find any reference to such in any of the parameters of the Rigidbody2D or Collider2D or Material.

As a workaround for the time being to keep the speed of the bouncy ball constant, I've included a line of code in FixedUpdate which manually sets the rigidbody's speed to a constant value:

void FixedUpdate () { rigidBodyRef.velocity = rigidBodyRef.velocity.normalized * 3; }

However, I wonder whether this manual setting of the rigidbody's speed interferes with Unity's physics engine, and whether there are any other undesirable consequences I'm not aware of. It certainly doesn't seem like a good way of creating a zero friction, zero drag, zero gravity 2D bouncy ball.

Comment
LOLinc

People who like this

1 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

  • Sort: 
avatar image

Answer by Arkaid · Jul 07, 2016 at 01:57 AM

I feel your pain.

Because of optimizations, the physics engine tends to kill some velocities on bounce when hitting at a small angle. It might help a bit if you go to Edit > Project Settings > Physics 2D then set your "Velocity Threshold" to its minimum possible value (0.0001).

That said, I ended up scrapping Unity's physics and using triggers and raycasting to calculate bounces myself.

Comment

People who like this

0 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 lerch23 · Jul 13, 2016 at 04:25 AM 0
Share

Many thanks Arkaid! I've just edited my question and added the workaround I applied for the time being, which is probably not great.

Would you mind sharing your solution, i.e. use of triggers and raycasting to calculate bounces?

Also, just to clarify: so the loss of velocities on bounce at small angles is a known and accepted issue in Unity? There is no intention to fix it within Unity?

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem - 2D Physics changed? -1 Answers

How to get the speed of an object? 3 Answers

How to make paddle influence ball motion in brickbreaker 0 Answers

Simple question about unity 5 rigidbody/gravity 1 Answer

Tank projectile speed 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