How to get particles in a group? - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Softbody (https://obi.virtualmethodstudio.com/forum/forum-12.html) +--- Thread: How to get particles in a group? (/thread-3799.html) |
How to get particles in a group? - tegleg - 14-03-2023 Hi as the title says how do i get particles in a group from code? would it be possible to post a snippet to illustrate how its done? ultimately im looking to get the position of said particles thanks RE: How to get particles in a group? - josemendez - 14-03-2023 (14-03-2023, 01:07 PM)tegleg Wrote: Hi Hi! A ObiParticleGroup contains a list of particle indices that you can just iterate: Code: var group = rope.blueprint.groups[0]; RE: How to get particles in a group? - tegleg - 14-03-2023 thank you how do i get them with the group name? RE: How to get particles in a group? - josemendez - 14-03-2023 (14-03-2023, 04:23 PM)tegleg Wrote: thank you They're stored in a plain list, so you just loop trough the groups until you find the one with the name you're interested in. There's usually not enough groups that O(N) lookup time by name would pose any problem. If it does (for example because you have thousands of groups and you need to look them up by name very often) you can insert them in a dictionary to look them up in constant time. RE: How to get particles in a group? - tegleg - 14-03-2023 ok thanks is it possible to addforce to an individual particle? or add force at position (giving the particle position)? edit, solved it by deconstructing AddForce() and applying force to a single particle instead of them all RE: How to get particles in a group? - josemendez - 14-03-2023 (14-03-2023, 06:01 PM)tegleg Wrote: ok thanks Yes, it’s possible. You can get/set particle positions velocities, masses, forces and a lot other properties. See the particles API in the manual: http://obi.virtualmethodstudio.com/manual/6.3/scriptingparticles.html RE: How to get particles in a group? - tegleg - 14-03-2023 thanks is this best done in FixedUpdate? there seems to be some fighting going on RE: How to get particles in a group? - josemendez - 15-03-2023 (14-03-2023, 09:54 PM)tegleg Wrote: thanks Depends on where you're updating your solver. There's several ObiUpdater components available in Obi, the default one is ObiFixedUpdater so yes, setting particle properties in FixedUpdate is a good option. If you want your code to work regardless of where you're updating physics, you can also use Obi's own solver callback events: http://obi.virtualmethodstudio.com/manual/6.3/scriptingsolver.html (14-03-2023, 09:54 PM)tegleg Wrote: there seems to be some fighting going on What do you mean "fighting"? RE: How to get particles in a group? - tegleg - 15-03-2023 maybe substep is the right option, i had to do this with unreal engine in the past to make it behave. how would i add force from another script in substep? perhaps i need to explain what i am doing i am attempting to create essentially a hover vehicle using raycast suspension. the raycast starts from a particle on each corner and applies upwards force to the corner particles. the technique works fine with unity's rigid body but produces 'jiggle' on the softbody. it is fighting the external forces. i copied the code from AddForce() but apply it to a single particle like this Code: body.solver.externalForces[particleindex] += suspensionForce / body.solver.invMasses[particleindex]; edit: this works. thanks for the help Code: void Actor_OnPreSolverStep(ObiActor actor, float stepTime) |