Help Obi Solver OnCollision - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html) +--- Thread: Help Obi Solver OnCollision (/thread-3161.html) |
Obi Solver OnCollision - ProDea - 02-11-2021 Hello everyone, Is there any way to take particle color of collided fluid on OnCollision event? RE: Obi Solver OnCollision - josemendez - 02-11-2021 (02-11-2021, 01:34 PM)ProDea Wrote: Hello everyone, Yes, exact same way you'd take any other particle property upon collision: Code: var color = solver.colors[particleIndex]; Note however, this assumes the color of your fluid comes from particle color only. The final fluid color is calculated as: Quote:particle renderer color * particle color So if the color of your fluid comes from emitter or renderer color, you'll have to get which actor (emitter) the particle belongs to, then pick the color up from there. This can also be done, see "Retrieving the actor involved in a contact" in the manual: http://obi.virtualmethodstudio.com/manual/6.2/scriptingcollisions.html RE: Obi Solver OnCollision - ProDea - 02-11-2021 So is it something like this? Code: private void OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e) This gives me the correct color which is 0,1,0 Green in that case. But GetComponent calls so much. Is it actually the most optimized way to get particle color or am I missing something over here? I tried this too but it gives me 1,1,1 White color. I have fluid renderer in the scene on MainCamera and (On ObiEmitter object) Obi Particle Renderer has green color 0,1,0. Code: private void OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e) RE: Obi Solver OnCollision - josemendez - 02-11-2021 (02-11-2021, 02:35 PM)ProDea Wrote: So is it something like this? Your code is correct, fluid color in your case comes from the particle renderer. Particles are all white, so: fluidColor = renderer color * particle color = (0,1,0) * (1,1,1) = (0,1,0). (02-11-2021, 02:35 PM)ProDea Wrote: I tried this too but it gives me 1,1,1 White color. I have fluid renderer in the scene on MainCamera and (On ObiEmitter object) Obi Particle Renderer has green color 0,1,0. Yes, this is correct and to be expected. Your particles are completely white, and being tinted green by the ObiParticleRenderer just before rendering. If you set the ObiParticleRenderer white and your ObiEmitterShape green, then the emitted particles will be green, and tinted white like so: fluidColor = renderer color * particle color = (1,1,1) * (0,1,0) = (0,1,0). This would allow you to get rid of the GetComponent<> calls entirely. Note in your first script you could just cache the component if you wanted, no need to call GetComponent for every single contact like that. RE: Obi Solver OnCollision - ProDea - 02-11-2021 Thank you so much for quick response! I changed color with Use Shape Color and it worked out |