Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Particle Collision API indexing wrong?
#1
Using the example I added gizoms to debug some weird behavior I was seeing;
[Image: DIES4.png?trs=2f6602c6f954098069b38316a7...d4c41f5ae6]
Code;
Code:
public class ZeroGravityZone : MonoBehaviour
{
    [SerializeField]
    private ObiSolver solver;
    public float antiGravityScale = 2;

    ObiSolver.ObiCollisionEventArgs collisionEvent;

    [AutoProperty, SerializeField, ReadOnly]
    private Collider antiGravityCollider;

    void OnEnable()
    {
        solver.OnCollision += Solver_OnCollision;
    }

    void OnDisable()
    {
        solver.OnCollision -= Solver_OnCollision;
    }

    private List<Vector3> collisionPositions = new List<Vector3>();

    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        // calculate an acceleration that counteracts gravity:
        Vector4 antiGravityAccel = -(Vector4)solver.parameters.gravity * antiGravityScale * Time.deltaTime;

        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;

                // if this is the antigravity trigger;
                if (col != null && col.gameObject.GetComponent<Collider>() == antiGravityCollider)
                {
                    // get the index of the particle involved in the contact:
                    int particleIndex = solver.simplices[contact.bodyA];

                    // set the particle velocity:
                    solver.velocities[particleIndex] += antiGravityAccel;
                    Debug.DrawLine(solver.positions[particleIndex], contact.pointB, Color.green);
                    collisionPositions.Add(solver.positions[particleIndex]);
                }
            }
        }
    }
    private void OnDrawGizmos()
    {
        foreach (var position in collisionPositions)
        {
            Gizmos.DrawSphere(position, 0.1f);
        }
        collisionPositions.Clear();
    }
}

Why is the colission not correct? I made sure the solver and rope pos, rot, and scale are 0.
Reply


Messages In This Thread
Particle Collision API indexing wrong? - by TheMunk - 12-08-2021, 01:48 PM