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 Marioooo · May 02, 2018 at 11:51 PM · collisionphysics2dcollider2dtriggers

double collision detection in breakout game

Hi! im making an arkanoid clone, and im having some issues with the ball physics... since i noticed that unity's physics system doesnt work as i need, i decided to create my own. im using walls with tags and only trigger colliders to detect where the ball hits and change its direction... but on corners i found that when detects 2 colisions (becouse im using 2 colliders for side and top walls) it jus picks one and ignores the other one... when this happends the ball just go out of bounds becouse ignores one of the walls instead of go exacly on the opposite way as it should do...
Im using the OnTriggerEnter2D void to make the collisions but it just executes one time per frame.. its any way to execute it twice? or is there a collision list to know how many and wich objects im colliding with? thanks!!

Comment
Add comment · Show 2
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 MacDx · May 03, 2018 at 04:17 PM 0
Share

Hi! Could you please show the code you're using for the ball's movement and collision?

Edit: I did a small test with these 2 classes and everything worked fine, even when both OnTriggerEnter2Ds happened in the same frame.

 public class Wall : $$anonymous$$onoBehaviour
 {
     public Vector2 normal;
 }
 
 public class Ball : $$anonymous$$onoBehaviour
 {
     public Vector2 direction;
     public float speed;
     private int frame;
 
     void Start()
     {
         frame = 0;
     }
 
     void Update()
     {
         frame++;
         Vector2 pos = transform.position;
         pos += direction.normalized * speed * Time.deltaTime;
         transform.position = pos;
     }
 
     void OnTriggerEnter2D(Collider2D other)
     {
         Wall wall = other.GetComponent<Wall>();
         if (wall == null) return;
         Debug.Log("Frame: " + frame);
         direction = Vector2.Reflect(direction, wall.normal);
     }
 }

Take a look: https://imgur.com/sa2oXLJ

avatar image Bunny83 · May 03, 2018 at 08:13 PM 0
Share

Right, just as $$anonymous$$acDx said there should be no problem with the OnTriggerEnter methods. If you have issues it's more likely a problem with your collision response. Solving collisions can be much more difficult than just changing the direction of movement depending on the placement of your walls. At the time OnTriggerEnter is called your colliders overlap. If the new direction does not successfully seperate the colliders you won't get a new TriggerEnter until they were completely seperated.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Koyemsi · May 05, 2018 at 01:52 AM

Hi. To know what the ball has collided with, its script should have :

void OnTriggerEnter2D (Collider2D coll) { print ("Ball collided with " + coll.name); }

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.

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

Performance of player detection: Colliders/Triggers vs OverlapCircle 2 Answers

problem solving ghost vertices with trigger and collision colliders 0 Answers

Physics2D.IgnoreCollision not working! 0 Answers

Ignore collision at the start of the game. 1 Answer

My OnCollisionEnter says i have 128 Collisions every collision 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