Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 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 TheUltragon · Oct 08, 2021 at 11:15 AM · rigidbody2dphysics2dcollider2dcircle

2D physics object acts weird when pressed into other physics object

The problem is in this video: https://youtu.be/7G9gqGObcb4

Setup: I have a simple game where you catch basketballs with a hoop that follows your mouse/touch input. The hoop is controlled via rb2d.MovePosition. The ball gets instantiated on top of the viewport and just falls down via standard physics. Also there are colliders situated at the edges of the screen.

Now when I try to push the hoop into the ball, the ball gets squeezed against the screenedge collider, but the hoop weirdly enough moves away from the ball. I want the squeezing to happen, but why is the hoop moving away?

Relevant stuff:

 public class FollowMouse : MonoBehaviour
 {
     public bool FollowX = true;
     public bool FollowY = false;
     public bool FollowZ = false;
 
     public float xMin = 0;
     public float xMax = 0;
 
     public float yMin = 0;
     public float yMax = 0;
 
     public float zMin = 0;
     public float zMax = 0;
 
     private Rigidbody2D rb2d;
 
     // Start is called before the first frame update
     void Start()
     {
         rb2d = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update()
     {
         Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         Vector3 position = transform.position;
 
         float x = FollowX ? mousePos.x : position.x;
         float y = FollowY ? mousePos.y : position.y;
         float z = FollowZ ? mousePos.z : position.z;
 
         if(FollowX)
             x = Mathf.Clamp(x, xMin, xMax);
 
         if(FollowY)
             y = Mathf.Clamp(y, yMin, yMax);
 
         if(FollowZ)
             z = Mathf.Clamp(z, zMin, zMax);
 
         Vector3 newPosition = new Vector3(x,y,z);
 
         //Important: Use rigidbody MovePosition, otherwise physics get wonky
         rb2d.MovePosition(newPosition);
     }
 }

Setup and Hoop in Inspector: Setup and Hoop

Ball in Inspector: Ball

The bouncing ball physics material has friction of 0.4 and bounciness of 0.8.

ball.jpg (61.7 kB)
setup-hoop.jpg (167.3 kB)
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 TheUltragon · Oct 08, 2021 at 11:41 AM 0
Share

Found out that it is because of the bounciness of the physics material. Is there any way I can go around that without removing the bounciness of the ball? I tried to make the edges of the hoop bouncy instead of the ball, but that lead to a host of other problems which made the physics even worse. Anyone any idea?

0 Replies

· Add your reply
  • Sort: 

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

135 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

Related Questions

Weird behaviour after Collision? 0 Answers

Using child colliders with rigidbodies/joints in 2D 0 Answers

Velocity doesnt change properly 1 Answer

Can a collider be solid along one axis only? 2 Answers

How do i stop rigidbody2D bounce 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