Help Collision detection with particles (strange behaviour) - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help Collision detection with particles (strange behaviour) (/thread-3046.html) |
Collision detection with particles (strange behaviour) - immrkuby - 05-08-2021 Code: private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e) Code: public void TearRope(int particleIndex) Hi ! I am working on a project and using ObiRope. I have problem with detecting collision with particles. I read documents and tried to use them as best as I can. I need to know which particle collided with a object that has specific layer. And I want to tear the rope at collided particles. Here is some screenshots for explaining it better. At right (teared rope) image behaviour acts like I want. But after I spawn new ropes it doesn't work. When I am Debug.Log the shown indexes are beyond existing particle count (I may be wrong in here.). If you need any additional info please tell me, I don't want to scare people with a long post Thank you ! I think I solved it . Just changed parameter "particleIndex" to "this.solver.particleToActor[particleIndex].indexInActor" I think I solved it . Still don't have idea why it didn't work. Code: private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e) RE: Collision detection with particles (strange behaviour) - josemendez - 06-08-2021 (05-08-2021, 09:09 PM)immrkuby Wrote: Just changed parameter "particleIndex" to "this.solver.particleToActor[particleIndex].indexInActor" Sonrisa I think I solved it Gran sonrisa. Still don't have idea why it didn't work. particleIndex is the index of a particle in the solver. this.solver.particleToActor[particleIndex].indexInActor is the index of the particle in an actor. It's two entirely different things. From the manual, scripting particles section: Quote:Actor particle indices run from 0 to the amount of particles in that actor. However, since particle data for an actor might be scattered across the solver arrays, you need to map from actor index to solver index. Say you have 3 actors: the first one has 5 particles, the second one has 3, and the third one has 4. Actor particle indices for them are 0-4, 0-2 and 0-3. But the solver (that stores all particle data) might have assigned completely different indices for them. Particles for the first actor might have their data stored at indices 21,33,34 and 36, the second one 3,5 and 9, and the third one 1,2,4 and 6, in the solver arrays. To access per-actor data you'd use actor indices (particleIndex in your case). To access the main solver arrays (positions, velocities, orientations, etc) you'd use solver indices. Also, your TearAtIndex() method doesn't make any sense. You're using the index of a particle in the actor to look up an array of elements. If this works, it's purely out of luck. Will result in an out of bounds exception most of the time. Code: if (index < rope.elements.Count) Elements are the "edges" in between particles, that hold them together. Each element joins exactly two particles together, so it has two solver indices in it. You should iterate trough all elements until you find the one that references your particle. Like so: Code: void TearAtIndex(int index) //<---pass a solver index here, that is your particleIndex. RE: Collision detection with particles (strange behaviour) - immrkuby - 06-08-2021 (06-08-2021, 08:14 AM)josemendez Wrote: particleIndex is the index of a particle in the solver. this.solver.particleToActor[particleIndex].indexInActor is the index of the particle in an actor. It's two entirely different things. From the manual, scripting particles section: Thank you very much ! I was confused at "But the solver (that stores all particle data) might have assigned completely different indices for them." and now things become clearer ! |