Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 unity_qT8Y9osPinb1jA · Mar 07 at 09:08 AM · collisionphysics2drigidbody.velocitybouncinessphysicsmaterial

PhysicsMaterial2D and bounciness: Getting weird angles when hitting box collider edges

Hi all,

I'm building a 2D brick breaker game and I'm using PhysicsMaterial2D in the ball. Friction is set to 0 and bounciness is set to 1. The ball has a circle collider and a dynamic rigidbody with continuous collision detection.

The bricks are static rigidbodies with a box collider. The behavior that I want for the collision is to preserve the ball's rigidbody velocity and invert its X or Y depending if the ball collided with sides or top/bottom of the brick.

The issue is that I'm getting weird angles when the ball hits the edge of the bricks or between two bricks. Here's a video: https://drive.google.com/file/d/1kpiHxU_yQCxIGA68ziag9ho1p2NlCact/view

Here's the code I'm using to debug this:

 void Update()
 {
 
     GetVelocity();
 
     if (brickCollisions > 0)
         brickCollisions = 0;
 }
 
 void GetVelocity()
 {
     lastFrameVelocity = rb.velocity;
 }
     void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag == "Common Brick")
     {
 
         brickCollisions++;
         Debug.Log("Brick collisions: " + brickCollisions + " / " + "Velocity before collision: " + lastFrameVelocity + " / " + "Velocity after collision: " + rb.velocity);
 
     }
 
 }

And here's an example (not the same as video) of what's happening when the ball hits edges:

 Brick collisions: 1 / Velocity before collision: (2.0, 2.0) / Velocity after collision: (2.0, -2.0)
 
 Brick collisions: 1 / Velocity before collision: (2.0, -2.0) / Velocity after collision: (2.0, 2.0)
 
 Brick collisions: 1 / Velocity before collision: (2.0, 2.0) / Velocity after collision: (0.2, -2.8)
 
 Brick collisions: 1 / Velocity before collision: (0.2, -2.8) / Velocity after collision: (-0.9, 2.7)
 
 Brick collisions: 1 / Velocity before collision: (-0.9, 2.7) / Velocity after collision: (-0.9, -2.7)


And this is when the ball hits between two bricks (which can very well be the same issue as above):

 Brick collisions: 1 / Velocity before collision: (2.0, 2.0) / Velocity after collision: (2.0, -2.0)
 
 Brick collisions: 1 / Velocity before collision: (2.0, -2.0) / Velocity after collision: (2.0, 2.0)
 
 Brick collisions: 1 / Velocity before collision: (2.0, 2.0) / Velocity after collision: (2.0, -2.0)
 
 Brick collisions: 1 / Velocity before collision: (2.0, -2.0) / Velocity after collision: (-0.9, 2.7)
 
 Brick collisions: 2 / Velocity before collision: (2.0, -2.0) / Velocity after collision: (-0.9, 2.7)
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
0
Best Answer

Answer by unity_qT8Y9osPinb1jA · Mar 08 at 10:33 PM

Okay, so I finally got around this issue with the amazing help of r/unity.

The solution was to replace the circle collider on the ball gameObject with a box collider. I made its size 0.8 so it's not noticeable for players and the angles I'm getting are consistent. I tested this several times today and I'm happy with the results.

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 unity_qT8Y9osPinb1jA · Mar 07 at 09:20 PM

If anyone has an explanation for this behavior, please let me know.

I don't expect anyone to write code or give me a solution, I just need to understand why this is happening and how to mitigate that.

Is this fixable if I change Physics2D settings?

Any tutorial, link to the API documentation or ideas are welcome. I've been reading old topics about bounciness and circle colliders but I haven't found a good answer yet.

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

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

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

2D Physics: Circle's velocity vector becomes parallel to collider's edge after collision with small angle 0 Answers

When I use Physics2D collider, Bounciness of 1 is slightly wrong. 0 Answers

Predicting projectile path after bouncing off Physics Material 2D 1 Answer

Jump implementation in multi level platforms game 1 Answer

Check if player is on track 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