04-10-2021, 01:34 PM
(This post was last modified: 04-10-2021, 01:43 PM by josemendez.)
Hi!
You're accessing the particle in the middle of the rope's particle pool. This is not the particle physically in the middle of the rope. You made the assumption that particles are guaranteed to appear in the arrays in the same order they appear in the rope, but that's not the case.
Also, usually the particle pool is much larger than the amount of active particles (by default, 100 + amount of particles in the rope). Particles in the pool might be active (in use by the rope) or inactive (not yet used). As you resize the rope using a cursor, or tear it, more particles will become active. Think of it just like a regular particle system: particles might be "alive" or "dead" and transition between these two states, but the total amount of particles allocated is always the same.
You want to get the element at the center of the rope, pick the particle at either end of the element, and use that. Also, no need to access the actor by index. Usually you already have a reference to the rope component around. Putting it all together:
Edit: If your rope has say, 12 particles and your blueprint's pooledParticles property is the defaultĀ (100), rope.solverIndices length is 112. So your original code is reading the position of particle 56 (which is inactive, so it has zero velocity).
Your second attempt is better, as you're using the amount of active particles in the rope (in my example, 12), and accessing the last one. However if you resize the rope or cut it, particles will be reordered so your code will cease working. The proper way to reason about the rope's topology is using elements, since particles can appear in any order.
You're accessing the particle in the middle of the rope's particle pool. This is not the particle physically in the middle of the rope. You made the assumption that particles are guaranteed to appear in the arrays in the same order they appear in the rope, but that's not the case.
Also, usually the particle pool is much larger than the amount of active particles (by default, 100 + amount of particles in the rope). Particles in the pool might be active (in use by the rope) or inactive (not yet used). As you resize the rope using a cursor, or tear it, more particles will become active. Think of it just like a regular particle system: particles might be "alive" or "dead" and transition between these two states, but the total amount of particles allocated is always the same.
You want to get the element at the center of the rope, pick the particle at either end of the element, and use that. Also, no need to access the actor by index. Usually you already have a reference to the rope component around. Putting it all together:
Code:
int index = rope.GetElementAt(0.5f).particle1;
Vector3 vel = rope.solver.velocities[index];
Edit: If your rope has say, 12 particles and your blueprint's pooledParticles property is the defaultĀ (100), rope.solverIndices length is 112. So your original code is reading the position of particle 56 (which is inactive, so it has zero velocity).
Your second attempt is better, as you're using the amount of active particles in the rope (in my example, 12), and accessing the last one. However if you resize the rope or cut it, particles will be reordered so your code will cease working. The proper way to reason about the rope's topology is using elements, since particles can appear in any order.