I have this oncollision code:
private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
foreach (var contact in e.contacts)
{
if (contact.distance < 0.025f)
{
var collision = world.colliderHandles[contact.bodyB].owner;
...
var particleIndex = solver.simplices[contact.bodyA];
var contactedRope = (ObiRope)solver.particleToActor[particleIndex].actor;
and after
private int GetParticleNeighborIndex(int particleIndex, int offset)
{
var solverIndex = rope.solverIndices[particleIndex];
var elementCount = rope.elements.Count;
int index;
var e = 0;
for (; e < elementCount; ++e)
if (rope.elements[e].particle1 == solverIndex)
break;
if (e == elementCount - 1 && offset > 0)
index = rope.elements[e].particle2;
else
{
var n = Mathf.Clamp(e + offset, 0, elementCount - 1);
index = rope.elements[n].particle1;
}
if (index > _lastParticleIndex && offset > 0) index = _lastParticleIndex;
return index;
}
But as soon as I have 2 ropes in the same Solver, I get a crash:
IndexOutOfRangeException: Index was outside the bounds of the array.
CreateClimbableObiRope2D.GetParticleNeighborIndex (System.Int32 particleIndex, System.Int32 offset) (at Assets/KLGames/ClimbObiRope/Scripts/CreateClimbableObiRope2D.cs:699)
What is the probleme here?
the crash is in this line
var solverIndex = rope.solverIndices[particleIndex];
IndexOutOfRangeException: Index was outside the bounds of the array.
(particleIndex is 130 but the solverIndices.length is only 87)
How can get back the REAL PARTICLE INDEX?
Thanks
private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
{
var world = ObiColliderWorld.GetInstance();
foreach (var contact in e.contacts)
{
if (contact.distance < 0.025f)
{
var collision = world.colliderHandles[contact.bodyB].owner;
...
var particleIndex = solver.simplices[contact.bodyA];
var contactedRope = (ObiRope)solver.particleToActor[particleIndex].actor;
and after
private int GetParticleNeighborIndex(int particleIndex, int offset)
{
var solverIndex = rope.solverIndices[particleIndex];
var elementCount = rope.elements.Count;
int index;
var e = 0;
for (; e < elementCount; ++e)
if (rope.elements[e].particle1 == solverIndex)
break;
if (e == elementCount - 1 && offset > 0)
index = rope.elements[e].particle2;
else
{
var n = Mathf.Clamp(e + offset, 0, elementCount - 1);
index = rope.elements[n].particle1;
}
if (index > _lastParticleIndex && offset > 0) index = _lastParticleIndex;
return index;
}
But as soon as I have 2 ropes in the same Solver, I get a crash:
IndexOutOfRangeException: Index was outside the bounds of the array.
CreateClimbableObiRope2D.GetParticleNeighborIndex (System.Int32 particleIndex, System.Int32 offset) (at Assets/KLGames/ClimbObiRope/Scripts/CreateClimbableObiRope2D.cs:699)
What is the probleme here?
the crash is in this line
var solverIndex = rope.solverIndices[particleIndex];
IndexOutOfRangeException: Index was outside the bounds of the array.
(particleIndex is 130 but the solverIndices.length is only 87)
How can get back the REAL PARTICLE INDEX?
Thanks