19-10-2021, 10:26 AM (This post was last modified: 19-10-2021, 10:28 AM by Matbee.)
Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks
(19-10-2021, 10:26 AM)Matbee Wrote: Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks
Hi there,
Blueprints are similar to prefabs: they're just "instructions" to build (instantiate) a rope. At runtime, particle data is contained in the solver.
19-10-2021, 11:00 AM (This post was last modified: 19-10-2021, 11:22 AM by Matbee.)
(19-10-2021, 10:26 AM)Matbee Wrote: Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks
Can't I get the global position of a particle in space? And in general, if, for example, I have a very small value for the number of particles, how can I get, for example, a point from the middle of the rope?
(19-10-2021, 10:26 AM)Matbee Wrote: Hello everyone, I want to know if my ropes are crossing, for that I want to check the position of the leftmost and rightmost points of my rope, how can I access all the points of my rope? I tried to get them through ObiRopeBlueprints points array, but nothing came of it, it displays the length of 0. Thanks
_rope.solver.actors[0].particleCount. I got the number of particles of the actor, but the list of all particles how can i get?
(19-10-2021, 11:00 AM)Matbee Wrote: And in general, if, for example, I have a very small value for the number of particles, how can I get, for example, a point from the middle of the rope?
You can just take the element at the middle of the rope, and get either particle at its ends. The following code would return the position of the particle in the middle, expressed in world space:
Code:
int particleIndex = rope.elements[rope.elements.Count/2].particle1;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[particleIndex]);
(19-10-2021, 11:24 AM)josemendez Wrote: Yes of course! you can express particle data in any space you'd like, including world space. Just use Unity's TransformPoint/Vector/Direction methods: https://docs.unity3d.com/ScriptReference...Point.html
You can just take the element at the middle of the rope, and get either particle at its ends. The following code would return the position of the particle in the middle, expressed in world space:
Code:
int particleIndex = rope.elements[rope.elements.Count/2].particle1;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[particleIndex]);
Do I understand correctly that each rope element contains 2 particles? Particle1 and particle2?
19-10-2021, 11:47 AM (This post was last modified: 19-10-2021, 11:48 AM by Matbee.)
(19-10-2021, 11:29 AM)josemendez Wrote: Correct. Each element is an "edge" joining 2 particles together, like this:
O-----O-----O-----O-----O
"O" being particles, and "-----" being elements.
I got it to display several different positions for all particles, but most of the particles have the same position as in the screenshot below
I also created a small sphere at each position, as you can see, some spheres were created at the correct position, but most of them were created at the point (0,0,1.8)
(19-10-2021, 11:29 AM)josemendez Wrote: Correct. Each element is an "edge" joining 2 particles together, like this:
19-10-2021, 12:02 PM (This post was last modified: 19-10-2021, 12:05 PM by josemendez.)
(19-10-2021, 11:47 AM)Matbee Wrote: I got it to display several different positions for all particles, but most of the particles have the same position as in the screenshot below
Yes, those are the pooled (inactive) particles. Quoting myself:
Quote:For instance, to print the solver-space position of all particles (including inactive ones):
Code:
for (int i = 0; i < actor.solverIndices.Length; ++i)
{
Debug.Log(solver.positions[actor.solverIndices[i]]);
}
A certain amount of extra particles are preallocated when you create a rope blueprint. These are collectively referred to as the particle "pool", and start out inactive (invisible, and not used in the simulation). If you do not plan on resizing or cutting the rope at runtime, you can set the blueprint's pool size to zero. No inactive particles will be added to the rope.
The reason for preallocating particles and activating/deactivating them instead of just creating/destroying particles at runtime is -as with most pooling strategies in Unity- to avoid runtime allocation and minimize garbage collection. See: http://obi.virtualmethodstudio.com/manua...setup.html
Quote:Pooled particles:
(Ropes only). Extra particles allocated to be used when tearing or resizing the rope. You can set this value to zero if you do not plan on tearing or resizing the rope at runtime, as no extra particles besides the initial ones will be needed.
Assuming you do have a non-empty pool, if you want to only get the active particles you should do:
Code:
for (int i = 0; i < actor.activeParticleCount; ++i)
{
Debug.Log(solver.positions[actor.solverIndices[i]]);
}