Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by rrh · Sep 14, 2012 at 12:10 AM · physicsrigidbodycolliderbreakout

Bounce collision vs. constrained rigidbody

Okay, sort of nooby.

For my first real game I'm trying a Breakout/Arkanoid style thing, and I'm trying to work out the physics of this.

My paddle has a constrained rigidbody, but when the ball collides with that, it absorbs the entire collision. The ball doesn't bounce back at all.

Everything has a material bounciness of 1, and if I don't have a rigidbody on it, it's fine. Except I was using the rigidbody on the paddle to keep it in the bounds of the playfield, and without it, I'm moving the paddle through translate() rather than through its velocity, and I think moving it by velocity will be better for the case when the ball clips the corner of the moving paddle.

So is there an alternate way to constrain the position of the paddle or what should I try to ensure the bounciness of the ball?

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
1
Best Answer

Answer by justinl · Sep 18, 2012 at 03:02 AM

After discussion, the answer is:

  1. Set the paddle object as a RigidBody with Kinematic property checked.

  2. Use rigidbody.MovePosition() to control movement of the paddle.

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 justinl · Sep 16, 2012 at 03:33 AM

You could constrain the paddle position simply by defining your "left and right" bounds. For instance this would keep the paddle between 0 and 100 along the x-axis:

 if(myPaddle.transform.position.x > 100)
   myPaddle.transform.position.x = 100; //you can't set this value like this explicitly but this is just an example code
 else if (myPaddle.transform.position.x < 0)
   myPaddle.transform.position.x = 0;

EDIT

After discussion, the answer to the original question is:

  1. Set the paddle object as a RigidBody with Kinematic property checked.

  2. Use rigidbody.MovePosition() to control movement of the paddle.

Comment
Add comment · Show 7 · 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 justinl · Sep 16, 2012 at 02:30 AM 0
Share

ps - I think you'd have to set the new position as: myPaddle.transform.position = new Vector3(100, myPaddle.transform.position.y, myPaddle.transform.position.z);

avatar image rrh · Sep 17, 2012 at 03:07 PM 0
Share

Okay, but if the paddle has no velocity can I get the ball to rebound the same as if the paddle was moving?

Because there were things I liked about having a rigidbody collision, like how the ball responds to the current velocity of the paddle. But if I'm just moving with Translate, then it has no velocity.

avatar image justinl · Sep 17, 2012 at 03:27 PM 0
Share

You can still keep the paddle as a rigidbody and constrain it's axis.

avatar image rrh · Sep 17, 2012 at 08:05 PM 0
Share

But that takes me back to my first problem that a constrained rigidbody loses energy when it bounces a ball.

I made a video that shows the differences: https://vimeo.com/49625612

I like how the ball bounces off the static collider except for it doesn't change the velocity of the bounce or add spin when it's moving. I like how the ball bounces off the unconstrained rigidbody, except for how the paddle gets knocked out of position. And with the constrained rigidbody, the ball loses energy when it bounces, like it's not really conserving momentum.

I can approximate what I want by making a very heavy constrained paddle, but it will still lose a small amount of momentum, and if there's a nice way to hold the position of something while still conserving momentum, it would be nice to know about.

avatar image justinl · Sep 18, 2012 at 01:00 AM 0
Share

Your video is private by the way (I can't view it). Try putting a checkmark in the "$$anonymous$$inematic" property on the paddle rigid body. I think that'll solve your "getting knocked out of place" issue. As for maintaining momentum, you could set a $$anonymous$$imum velocity on the ball. So in your ball update script, you can make sure that the velocity parameter does not go below a certain value. This way, the ball can "speed up" if you hit it hard, but yet it will never slow down so much that it stops or becomes too slow.

Show more comments

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

10 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

Related Questions

How do I use rigidbody's collision detection modes? 2 Answers

Rigidbodies won't collide if mass difference is too high 0 Answers

Guidelines for using rigidbody, collider, CharacterControllerScript, etc? 3 Answers

How to get collisions on Character controller? 1 Answer

OnCollisionEnter isnt called when player lands on object 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