public void ReactCollision(ref List <RaycastHit2D> contacts, PhysicObject.CollisionStage stage) { if (stage == PhysicObject.CollisionStage.Before) { PreCollisionTest(ref contacts); } else { for (int i = 0; i < contacts.Count; ++i) { RaycastHit2D hit = contacts[i]; Vector2 cntNorm = contacts[i].normal; if (hit.collider.usedByEffector) {//rely on built in effector to avoid having to code a class that containt exactly the same parameters PlatformEffector2D effector = hit.collider.GetComponent <PlatformEffector2D>(); if (effector != null && effector.useOneWay) { if (HandlePassThroughPlatform(hit, effector, stage)) { contacts.RemoveAt(i); i--; } } } } } }
protected void HandleCollision(ref List <RaycastHit2D> contacts, PhysicObject.CollisionStage stage) { foreach (var hit in contacts) { if (Vector2.Dot(_forward, hit.normal) < -0.9f) { _collidedInMovement = true; } } }
//return true if need to be removed protected bool HandlePassThroughPlatform(RaycastHit2D hit, PlatformEffector2D effector, PhysicObject.CollisionStage stage) { Vector2 cntNorm = hit.normal; if (stage == PhysicObject.CollisionStage.XMove) { if (!_currentPlatformEffectors.Contains(hit.collider)) { _currentPlatformEffectors.Add(hit.collider); } return(true); } else { //only test if we are currently falling AND if we weren't going through that //effector the last frame already. Otherwise we ignore it (as that mean we started falling //before going entierly through it, we would get stuck in it if we weren't ignoring it) if (_po.velocity.y < 0) { if (!_currentPlatformEffectors.Contains(hit.collider)) {//if the current list of effector contain that effector, we never passed it completly, //don't collide as we would be stuck INSIDE it float dot = Vector2.Dot(cntNorm, Vector2.up); if (dot < Mathf.Cos(Mathf.Deg2Rad * effector.surfaceArc * 0.5f)) {// ignore that collision, the normal is outside the angle define return(true); } } else { return(true); } } else { if (!_currentPlatformEffectors.Contains(hit.collider)) { _currentPlatformEffectors.Add(hit.collider); } return(true); } } return(false); }