Help Spatial Query on multiple Actors - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: General (https://obi.virtualmethodstudio.com/forum/forum-5.html) +--- Thread: Help Spatial Query on multiple Actors (/thread-3239.html) |
Spatial Query on multiple Actors - cgwill - 20-12-2021 Hello, i have recently started to work with the Obi Package (Rope/Cloth) and am running in some trouble. It is probably a pretty simple fix/problem but i simply am unable to figure it out myself. I used the code example for spatial query which is working really perfectly as long as only one actor is in the solver. As soon as multiple actors from the same type are in the solver the position data is calculated wrong. It stays correct with the last actor in the solver though, which i find curious. Code: using UnityEngine; Here is a GIF of the problem Any suggestions why this might be? Does this concern the info in the example code (We're assuming the solver only contains 0-simplices (particles))? A follow up question would be. I plan on using multiple solvers with multiple actors in my scene and would keep the performance overhead low. What would be the best query method to check which actor/particles are near. Is the spatial query method suited for this purpose? Any help would be highly appreciated Best regards, Will RE: Spatial Query on multiple Actors - josemendez - 20-12-2021 Hi there Will! Code: solver.positions[results[i].simplexIndex] This will only work if you only have one actor per solver and it is not using surface collisions. To get a particle index from a simplex index in the general case, see "Retrieving the particle involved in a contact": http://obi.virtualmethodstudio.com/manual/6.3/scriptingparticles.html In your case, assuming you don't use surface collisions the code would be: Code: // no surface collisions, so we assume only one particle per simplex: If you do use surface collisions, the simplices used by queries and collisions will be groups of 2 particles each, so assuming there's only one particle per simplex no longer works. The general code to get all particles in a simplex (whether there's 1, 2 or 3 particles in the simplex) is: Code: // retrieve the offset and size of the simplex in the solver.simplices array: Since the code to do this for collisions and queries is exactly the same, I will add this info to the queries manual page too as I realized it can be misleading otherwise. Let me know if I can be of further help! RE: Spatial Query on multiple Actors - cgwill - 21-12-2021 Thank you so much for your swift reply. I managed to get it working with your help. I wish you relaxing holidays because i might take you up on that offer with further help in the new year cheers Will |