• 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
1
Question by Jahannam · May 19, 2011 at 06:11 AM · physicsbouncepong

Bouncing Ball and Walls

I am currently making a version of Pong with a little twist. Everything is going great so far, but if the ball is hit at a vertical/near vertical angle, it will continue to bounce between the two walls and pretty much stays there for the rest of the game. I have primarily made the game using built-in Physics materials, although the paddles and the walls are adding force to the ball when it collides with them(a feature of the game, to make it go faster). The ball has force applied to it at the start. I was wondering whether there would be anyway to prevent this "perfect bounce" scenario, and would be very grateful for any help.

Here are what the walls are doing (the opposite force for the bottom wall):

 function OnCollisionEnter (collision : Collision) {
 if (collision.gameObject == ball) {
         audio.PlayOneShot(WallBoink);
         
         collision.rigidbody.AddForce (0,-20,0);
     }
 }    

And here are what the paddles are doing (opposite force for opposing paddle):

 function OnCollisionEnter (collision : Collision) {
 if (collision.gameObject == ball) {
         audio.PlayOneShot(Boink);
         
         collision.rigidbody.AddForce (-20,0,0);
     }
 }    

Any help would be greatly appreciated.

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 Tijs · Jan 08, 2013 at 07:42 PM 0
Share

How did you make the ball move that way?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Muzz5 · May 19, 2011 at 09:11 AM

How about making some sort of bounce counter, which is reset after it hits a paddle, and if it bounces against the wall n times, then a force is added which goes sideways? Sorry if I didn't explain that too well, if you need me to write out the code I will.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Making Pong 1 Answer

Sphere Goes Crazy 3 Answers

Problem with Ball Bouncing after Collision 2 Answers

Bouncing objects and Energy loss 2 Answers

how to entirely prevent 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