Obi Official Forum
Rope that can be in water - Printable Version

+- Obi Official Forum (http://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (http://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (http://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Rope that can be in water (/thread-3168.html)



Rope that can be in water - lufydad - 09-11-2021

I made a game with an ocean and a whole physical system associated with it.

Is it possible to add forces on given particles in a rope ? That way I could identify the particles under water and add resistance force to them.


RE: Rope that can be in water - josemendez - 09-11-2021

(09-11-2021, 03:26 PM)lufydad Wrote: I made a game with an ocean and a whole physical system associated with it.

Is it possible to add forces on given particles in a rope ? That way I could identify the particles under water and add resistance force to them.

Yes, you can add forces to individual particles, and get/set any particle property. See:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html

You can also retrieve contact data and make spatial queries such as raycasts, box overlaps, etc:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingcollisions.html
http://obi.virtualmethodstudio.com/manual/6.2/scriptingqueries.html


RE: Rope that can be in water - lufydad - 09-11-2021

(09-11-2021, 03:56 PM)josemendez Wrote: Yes, you can add forces to individual particles, and get/set any particle property. See:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html

You can also retrieve contact data and make spatial queries such as raycasts, box overlaps, etc:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingcollisions.html
http://obi.virtualmethodstudio.com/manual/6.2/scriptingqueries.html

Thanks for your answer, indeed I didn't saw the property externalForces in ObiSolver.

Here is an example :

Code:
for (int i = 0; i < actor.solverIndices.Length; ++i)
{

     // retrieve the particle index in the solver:
     int solverIndex = actor.solverIndices[i];
     
     if(IsUnderWater(actor.solver.positions[solverIndex])
         actor.solver.externalForces[solverIndex] = MyForceForUnderWater;
     else
         actor.solver.externalForces[solverIndex] = MyForceForAboveWater;
}



RE: Rope that can be in water - josemendez - 10-11-2021

(09-11-2021, 04:56 PM)lufydad Wrote: Thanks for your answer, indeed I didn't saw the property externalForces in ObiSolver.

Hi!

The externalForces array is undocumented on purpose, since it is used internally by Obi's force zones. It's easy to break force zones by tinkering with it: your code overwrites the content of externalForces, so force zones will cease to work. You could fix this by adding the force instead of setting it to a fixed value.

Another option is to apply forces to the velocities array like this:

Code:
actor.solver.velocities[solverIndex] += MyForceForUnderWater * actor.solver.invMasses[solverIndex] * deltaTime;

Since F=ma, and acceleration is a change in velocity over time, your change in velocity is = F/m*dt.


RE: Rope that can be in water - lufydad - 10-11-2021

(10-11-2021, 10:14 AM)josemendez Wrote: Hi!

The externalForces array is undocumented on purpose, since it is used internally by Obi's force zones. It's easy to break force zones by tinkering with it: your code overwrites the content of externalForces, so force zones will cease to work. You could fix this by adding the force instead of setting it to a fixed value.

However, generally it's a better idea to apply forces to the velocities array like this:

Code:
actor.solver.velocities[solverIndex] += MyForceForUnderWater * actor.solver.invMasses[solverIndex] * deltaTime;

Since F=ma, and acceleration is a change in velocity over time, your change in velocity is = F/m*dt.

thank you for this clarification, it could indeed be useful Sonrisa