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 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 hit 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 this 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,anything 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--;
 
 }
 }

// hitting 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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how the ball bounces of equal in angles? 1 Answer

Bouncing Ball and Walls 1 Answer

Sphere Goes Crazy 3 Answers

How to make an infinite mass solid body 1 Answer

Reducing bounce on simple boxes 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