• 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 rimawi · Aug 14, 2011 at 09:44 PM · physicsbounce

pang clone game issues

Hi,

I am trying to make a pang clone game : bouncing balls you $$anonymous$$t them with harpoon like weapon they split into half.

-The walls are bouncy with 0 friction, the balls are rigidbodies.

My issues are:

1-collision between the balls I want them to ignore each others. ---they don't the first time then after the first collision they start ignoring

2-some times the ball get stuck on the y or x axis bouncing -how can I add some multiplier to avoid t$$anonymous$$s issue.

Here is the code:

 var impact : AudioClip;
 var minSpeed:float=5;
 var maxSpeed:float=10;
 var curSpeed:float=0;
 var colSpeedMulti:float=1.1;
 var myball:GameObject;
 
  
 
 function Start () {
 rigidbody.AddRelativeForce(0,-minSpeed,0);
 }
 
 
 function FixedUpdate () {
 
 curSpeed=Vector3.Magnitude(rigidbody.velocity);
 
 if(curSpeed > maxSpeed)
 {
 rigidbody.velocity /= curSpeed / maxSpeed;
 
 }
 
 
 if(curSpeed < minSpeed && curSpeed > 0)
 {
 rigidbody.velocity /= curSpeed / minSpeed;
 
 }
 }

///the collision function: //1-balls need to ignore each others,anyt$$anonymous$$ng else bounce

 function OnCollisionEnter(col:Collision){
 
 audio.PlayOneShot(impact);
 
 if(col.collider.gameObject.CompareTag("ball")){
 
 Physics.IgnoreCollision(col.collider,collider);
 }
 
 else{
 /// we need some multiplier to avoid getting stuck
 rigidbody.velocity += rigidbody.velocity * colSpeedMulti;
 
 
   
 //score.Score++;
 //lives.currentlives--;
 
 }
 }

// $$anonymous$$tting the balls with arrow // if they are not small enough split them otherwise destroy the ball

 function OnTriggerEnter (other : Collider) {
 if(other.gameObject.CompareTag("arrow"))
 {
 
 if(transform.localScale.y!=0.5){
 
 Destroy(other.gameObject);
 Destroy(gameObject);
 
 var ball=Instantiate(myball,transform.Find("span1").transform.position,Quaternion.identity);
 ball.transform.localScale /=2;
 var ball2=Instantiate(myball,transform.Find("span2").transform.position,Quaternion.identity);
 ball2.transform.localScale /=2;
 
 paddle.weaponactive=false;
 }
 else if(transform.localScale.y==0.5){
 
 Destroy(other.gameObject);
 Destroy(gameObject);
 paddle.weaponactive=false;
 }
 }
 }





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

1 Reply

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

Answer by Eric5h5 · Aug 14, 2011 at 09:48 PM

Use collision layers for the balls so they ignore each other.

Comment
Add comment · Show 5 · 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 rimawi · Aug 14, 2011 at 09:50 PM 0
Share

i am adding them at runtime and that will make it even harder

avatar image sneftel · Aug 14, 2011 at 09:52 PM 0
Share

Adding them at runtime does not make it harder. Just set the layer in the prefab.

avatar image rimawi · Aug 14, 2011 at 09:59 PM 0
Share

the problem at a point in the game i will have 16 balls running does that mean i need 16 different layers --Thanks

avatar image sneftel · Aug 14, 2011 at 10:23 PM 0
Share

No, it just means you need to make the "balls" layer not collide with itself.

avatar image rimawi · Aug 14, 2011 at 11:20 PM 0
Share

Thank you. issue 1 is solved. colllision is layer based.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Physics Problem :Collision(When ball moves from one ground (made of cube) to another ) 0 Answers

Bouncing not working 1 Answer

How can I show trajectory of a bouncing ball OnCollisionEnter/OnCollisionExit? 0 Answers

I have a sphere and a mesh (roulette table). Physics doesn't work. 2 Answers

How to keep player from bouncing off objects? 0 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