Hi there,
i was wondering, how to create an ParticleCollisionEvent in a OnParticleCollision function.
I can get the Particle collision via this function.
But i am not sure, how to build an ParticleCollisionEvent from this. Or how to get the Info from the collision from the code below.
My goal is to get aVector3 Intersection of the Collision, and the normal
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
for (int i = 0; i < e.contacts.Length; ++i)
{
if (e.contacts[i].distance < 0.001f)
{
Component collider;
if (ObiCollider.idToCollider.TryGetValue(e.contacts[i].other, out collider))
{
}
}
}
}
thx for any help
I actually got that to work, I used
e.contacts[i].point as the intersect Point
e.contacts[i].normal as the normal
(pretty obvious )
Now i just ran into another Problem. The OnParticleCollision triggers quite often, but I would rather like it to trigger it only on the first collision. What would be a good approach to achieve that behaviour?
Thx in regards,
A ObiFluid - Noob
Posts: 9
Threads: 4
Joined: Jan 2018
Reputation:
0
If you want it to trigger only once per particle, you can store the list of the already-processed particles in a HashSet within the class handling the collision (or anywhere you see fit). For each collision, you would check if contact.particle is not present in the set and then proceed with your collision logic, and then add the contact.particle ID into the HashSet for it to not be proceed ever again
Cheers
(29-01-2018, 05:06 PM)tooomg Wrote: If you want it to trigger only once per particle, you can store the list of the already-processed particles in a HashSet within the class handling the collision (or anywhere you see fit). For each collision, you would check if contact.particle is not present in the set and then proceed with your collision logic, and then add the contact.particle ID into the HashSet for it to not be proceed ever again
Cheers
Thx for your answer, its kind of working. The problem i have right now is, that maybe obi fluid is using some kind of object pooling, because my hashset is not getting new values at the size of 1414 everytime. Maybe thats the maxsize of particles in obifluid before it starts reusing old Particles. The problem is that i dont want to hardcode a clear of the hashset at 1414, because i don't really know where that number is coming from. Also performance is getting really bad, as the hashset grows..
Cheers
Posts: 9
Threads: 4
Joined: Jan 2018
Reputation:
0
(30-01-2018, 09:29 AM)UTFLuke Wrote: Thx for your answer, its kind of working. The problem i have right now is, that maybe obi fluid is using some kind of object pooling, because my hashset is not getting new values at the size of 1414 everytime. Maybe thats the maxsize of particles in obifluid before it starts reusing old Particles. The problem is that i dont want to hardcode a clear of the hashset at 1414, because i don't really know where that number is coming from. Also performance is getting really bad, as the hashset grows..
Cheers
I don't know how you setup your emitter, but my bet is that the life of some particles is over by the time you start emitting the 1414th one. So the emitter "deletes" the old one, and probably reuses their ID for the newly spawned one as it became available. So in the end, you never have more that 1414 particles at once.
About the hashset solution, it did work in my case because I was doing "one-shot" emission of all the particles and then turning off the spawner, so I wouldn't get a particle reuse some old ID. But if your emitter is continuously generating new ones, and their lifespan is not "infinite", that will probably not work as you would need a more unique ID than the particle ID which is reused.
What is the logic you are trying to achieve?
(30-01-2018, 01:06 PM)tooomg Wrote: I don't know how you setup your emitter, but my bet is that the life of some particles is over by the time you start emitting the 1414th one. So the emitter "deletes" the old one, and probably reuses their ID for the newly spawned one as it became available. So in the end, you never have more that 1414 particles at once.
About the hashset solution, it did work in my case because I was doing "one-shot" emission of all the particles and then turning off the spawner, so I wouldn't get a particle reuse some old ID. But if your emitter is continuously generating new ones, and their lifespan is not "infinite", that will probably not work as you would need a more unique ID than the particle ID which is reused.
What is the logic you are trying to achieve?
Yeah that what i am thinking too.
The logic I try to achieve is quite simple. I shoot obi particles in one direction. On the wall, where the Obi particles hit, i spawn some "Splat" Particles (standard unity particlesystem). But Obi fluid Particles are floating on the walls, thats why I only want to take the first Collision with the wall. Since the particle shooting works like a "water gun", you can shoot any amount of Particles you would like.
My problem is, that my splats particles are not spawning any more the after the 1414th Obi particle, since the obi particles are already in my hashset.
The reuse of the obi particles makes totally sence to me, performance wise. But I am really stuck with how I could spawn my splats at the first (and only the first) Collision with the wall.
Greets
Posts: 9
Threads: 4
Joined: Jan 2018
Reputation:
0
30-01-2018, 02:05 PM
(This post was last modified: 30-01-2018, 02:06 PM by tooomg.
Edit Reason: typos
)
(30-01-2018, 01:24 PM)UTFLuke Wrote: Yeah that what i am thinking too.
The logic I try to achieve is quite simple. I shoot obi particles in one direction. On the wall, where the Obi particles hit, i spawn some "Splat" Particles (standard unity particlesystem). But Obi fluid Particles are floating on the walls, thats why I only want to take the first Collision with the wall. Since the particle shooting works like a "water gun", you can shoot any amount of Particles you would like.
My problem is, that my splats particles are not spawning any more the after the 1414th Obi particle, since the obi particles are already in my hashset.
The reuse of the obi particles makes totally sence to me, performance wise. But I am really stuck with how I could spawn my splats at the first (and only the first) Collision with the wall.
Greets
Mmmh and why not deleting the particles as they splat on the wall? Are they supposed to be sticking on the wall? (like the sticking honey demo?). Maybe you could replace them with something more static at the collision location, so it doesn't need all the physic simulation Obi provides?
But if you do need to keep the particles around for the full duration of their lifespan, the more general issue is that you need to find a way to know when a particle has expired. A basic approach could be to check the lifespan of each particle in your HashSet on each frame, and clear the ones that are dead. You can do this by checking if emitter.life[particleIndex] is negative.
Hope this helps!
Cheers
|