16-10-2022, 07:27 PM
(This post was last modified: 16-10-2022, 08:16 PM by josemendez.)
(15-10-2022, 03:43 PM)Ropuska Wrote: I used this to see if there is any collisions before the ball hits, and there is on every update???
Hi!
You've subscribed to an event that is called every frame, providing a list of contacts that happened during that frame. Your original code does nothing with this list except check if it's null. Since it's never null, your Debug.Log will be printed every frame.
(15-10-2022, 03:43 PM)Ropuska Wrote: After the ball hits and stays on the rope nothing changes. I get this code block from another forum. The problem is nobody so far wanted to get the collider or gameobject info who's collided to rope so far.
The manual explains all of this in detail and also includes code snippets for you to use as a basis. These include getting the collider involved in a contact, in a section aptly named "retrieving the collider involved in a contact" :
http://obi.virtualmethodstudio.com/manua...sions.html
(16-10-2022, 04:09 PM)Ropuska Wrote: I found a problem.
1)In Solver_OnCollision() method both "for" and "foreach" methods are not working. So I cannot retrieve every contact info one by one to compare if they are actual collision contacts.
If the loops are not executing any iteration that's because the length of the list they're iterating trough is zero. This is probably because you've subscribed to solver.OnParticleCollision instead of solver.OnCollision. OnParticleCollision returns a list of particle-particle contacts, while OnCollision returns particle-collider contacts. Quoting the manual:
http://obi.virtualmethodstudio.com/manua...sions.html
Quote:Contacts can happen between a simplex and a collider, or between two simplices. To request the simplex-collider contact list from the solver, subscribe to its OnCollision event. To retrieve the simplex-simplex contact list, subscribe to its OnParticleCollision event.
(16-10-2022, 04:09 PM)Ropuska Wrote: 2)How did I found out? Simple I both in debugging mode and not in debugging mode the traversing through code is failing. The system directly jumps through end when it sees a for or foreach. Also "There is a contact" text never seen.
At first I thought maybe its a bug because IDE so I closed debugging and added debug.logs. Even after there is nothing.
As I pointed out above, this is because the amount of elements in the _contacts list is zero. Built-in control structures in a language (such as for loops) don't just randomly break or stop working, and the IDE has absolutely nothing to do with either the compiler or the debugger: it's just a "frontend" for both. So even if the IDE had a bug, that would not change the behavior of your code or alter step-by-step execution in any way.
(16-10-2022, 04:09 PM)Ropuska Wrote: 3)So I just wanted to take the first contact info. When I used _contacts[0].bodyB it shows the collider of collided object which is the thing I wanted at first. So I thought my problem was solved. As you can see it is not.
In a nutshell: Your for loop is working just fine, it's just that the loop will execute zero times since are no contacts to iterate trough, because you've subscribed to inter-particle contacts instead of collider contacts.
(16-10-2022, 04:09 PM)Ropuska Wrote: Why simple I can't compare every particles contact info without any loop.
There's no way to compare contact info on every particle without looping trough them. In any existing programming language you'd need a loop for this, there's just no way around it. Unity's built-in physics engine also uses a for loop internally to iterate trough all contacts, and then calls OnCollisionEnter() for each collider involved in it. This wouldn't work for a particle-based engine -like Obi- since it typically deals with *a lot* more contacts and it would result in very poor performance. In Obi you have raw access to the contacts list instead, which allows you to even process contacts using multiple threads in parallel if needed.
hope this gets you back on track, let me know if you need further help.
kind regards,