// ---------------------------------------------------------------- // DEPENDENT Updates // ---------------------------------------------------------------- //public void UpdateSurfaceDists() { // for (int side=0; side<NumSides; side ++) { // UpdateSurfaceDist(side); // } //} //private void UpdateSurfaceDist(int side) { // minDistsIndexes[side] = -1; // Default this to -1: There is no closest, because they're all infinity. // collSpeedsRel[side] = Mathf.NegativeInfinity; // nothing's moving towards me. // for (int index=0; index<NumWhiskersPerSide; index++) { // UpdateWhiskerRaycast(side, index); // update the distances and colliders. // float dist = surfaceDists[side,index]; // use the dist we just updated. // if (DistToSurface(side) > dist) { // Update the min distance, too. // minDistsIndexes[side] = index; // } // } // onSurfaces[side] = collsTouching[side].Count > 0; // Update onSurfaces! //} ///// wi: WhiskerIndex //private void UpdateWhiskerRaycast(int side, int wi) { // // Find the closest collider. // hits = GetRaycast(side, wi); // h = new RaycastHit2D(); // Collider2D coll = null; // for (int i=0; i<hits.Length; i++) { // Check every collision for ones we interact with... // if (DoCollideWithColl(hits[i].collider)) { // h = hits[i]; // coll = h.collider; // break; // } // } // // Update my knowledge! // float dist = DistToColl(h, WhiskerPos(side, wi)); // surfaceDists[side,wi] = dist; // collsAroundMe[side,wi] = coll; // UpdateCollSpeedsRel(side, coll); //} public void UpdateSurfaces() { for (int side = 0; side < NumSides; side++) { // Remember the previous colliders, and clear out the new list! pcollsTouching[side] = new HashSet <Collider2D>(collsTouching[side]); collsTouching[side].Clear(); UpdateSurface(side); } if (DirTouchingWall() != 0) { DirLastTouchedWall = DirTouchingWall(); } // Now that EVERY side's been updated, check: Have we STOPPED or STARTED touching an old/new collider? for (int side = 0; side < NumSides; side++) { foreach (Collider2D col in pcollsTouching[side]) { if (!collsTouching[side].Contains(col)) { myCharacter.OnWhiskersLeaveCollider(side, col); } } } for (int side = 0; side < NumSides; side++) { foreach (Collider2D col in collsTouching[side]) { if (!pcollsTouching[side].Contains(col)) { // Ignore collider? Skip it. if (myCharacter.IgnoreColl(side, col)) { continue; } myCharacter.OnWhiskersTouchCollider(side, col); } } } }