12-08-2021, 01:48 PM
Using the example I added gizoms to debug some weird behavior I was seeing;
Code;
Why is the colission not correct? I made sure the solver and rope pos, rot, and scale are 0.
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.