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 Andrii · Jan 24, 2017 at 02:34 AM · physicsphysics2dcollider2dcollisions

Physics2D bug or something I can avoid?

Here's an animation of what happens in my game. It always reproduces in conditions shown on this gif. It's a simple breakout clone where ball destroys the bricks. You can see that it successfully hits two bricks, but when it returns back to hit that long brick, it starts to slide along it.

The GIF

It looks like some kind of physics approximation bug/feature, but it's unacceptable for this kind of game because after this the ball will just keep at the same height and never reach the bottom of the screen.

Ball and all bricks have physics materials with friction=0 and bounciness=1. When it starts sliding it triggers OnCillisionEnter and only when ball stops touching the brick, it triggers Exit. Which isn't ok.

If I change velocity of the ball, it takes different trajectory and this doesn't happen, but when you play the game, sometimes this sliding bug will pop out of nowhere and make my game unplayable.

What's causing this? Is this fixable? If not, maybe there's a workaround?

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

3 Replies

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

Answer by Andrii · Jan 24, 2017 at 03:19 AM

Ok. I've found it.

It's Edit > Project Settings > Physics 2D > Velocity Threshold

Changing it from 0.1 to 0.01 fixes it for me. And from what I'm reading online, it's ok to set it to 0.0001 for this kind of game when the RigidBody is intended to never stop. This setting exists just to stop objects and stop calculating physics for them. But that's useful in a more chaotic game with more objects, not in a breakout game.

Also, I've found few other people complaining on the same issue while making a breakout game :)

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 Rocketman_Dan · Jan 24, 2017 at 11:25 AM

@Andrii Try making the brick collider a trigger and use OnTriggerEnter2D rather than OnCollisionEnter to detect when the ball touches it. This should prevent it from behaving like a physical collision and activate the code inside the method to execute.

This is an example of code that will make the brick disappear with no animation or embelishments. Just replace "Destroy(gameObject);" with whatever code you want to run on contact.

 void OnTriggerEnter2D()
 {
     Destroy(gameObject);
 }

Note that your ball would not naturally bounce on contact so you would have to apply some code to make that happen. Perhaps by taking the movement vector before the collision and mirroring it after collision.

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 Viiarge · Jan 24, 2017 at 09:33 AM

I had a similar issue and fixed it putting my OnCollisionExit2D logic into the OnCollisionStay2D method. Hope this can help.

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

98 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

Related Questions

Is it possible to rotate a 2d collider in 3d? 0 Answers

Using collider to gameobject detect attack or not 2 Answers

My OnCollisionEnter says i have 128 Collisions every collision 1 Answer

Mesh Colliders and 2D Colliders 1 Answer

Colliders2D not working under same parent? 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