private bool CheckCharacterCollision(Contact contact, Character character) { //characters that can't enter the sub always collide regardless of gaps if (!character.AnimController.CanEnterSubmarine) { return(true); } if (character.Submarine != null) { return(false); } contact.GetWorldManifold(out Vector2 contactNormal, out FixedArray2 <Vector2> points); Vector2 normalizedVel = character.AnimController.Collider.LinearVelocity == Vector2.Zero ? Vector2.Zero : Vector2.Normalize(character.AnimController.Collider.LinearVelocity); //try to find the hull right next to the contact point Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] - contactNormal * 0.1f); Hull newHull = Hull.FindHull(targetPos, null); //not found, try searching a bit further if (newHull == null) { targetPos = ConvertUnits.ToDisplayUnits(points[0] - contactNormal); newHull = Hull.FindHull(targetPos, null); } //still not found, try searching in the direction the character is heading to if (newHull == null) { targetPos = ConvertUnits.ToDisplayUnits(points[0] + normalizedVel); newHull = Hull.FindHull(targetPos, null); } var gaps = newHull?.ConnectedGaps ?? Gap.GapList.Where(g => g.Submarine == submarine); targetPos = character.WorldPosition; Gap adjacentGap = Gap.FindAdjacent(gaps, targetPos, 500.0f); if (adjacentGap == null) { return(true); } if (newHull != null) { CoroutineManager.Invoke(() => character.AnimController.FindHull(newHull.WorldPosition, true)); } return(false); }
private bool HandleLimbCollision(Contact contact, Limb limb) { if (limb.character.Submarine != null) { return(false); } Vector2 normal2; FixedArray2 <Vector2> points; contact.GetWorldManifold(out normal2, out points); Vector2 normalizedVel = limb.character.AnimController.Collider.LinearVelocity == Vector2.Zero ? Vector2.Zero : Vector2.Normalize(limb.character.AnimController.Collider.LinearVelocity); Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] - normal2); Hull newHull = Hull.FindHull(targetPos, null); if (newHull == null) { targetPos = ConvertUnits.ToDisplayUnits(points[0] + normalizedVel); newHull = Hull.FindHull(targetPos, null); if (newHull == null) { return(true); } } var gaps = newHull.ConnectedGaps; targetPos = limb.character.WorldPosition; Gap adjacentGap = Gap.FindAdjacent(gaps, targetPos, 200.0f); if (adjacentGap == null) { return(true); } var ragdoll = limb.character.AnimController; ragdoll.FindHull(newHull.WorldPosition, true); return(false); }
private bool CheckCharacterCollision(Contact contact, Character character) { //characters that can't enter the sub always collide regardless of gaps if (!character.AnimController.CanEnterSubmarine) { return(true); } if (character.Submarine != null) { return(false); } contact.GetWorldManifold(out Vector2 contactNormal, out FixedArray2 <Vector2> points); Vector2 normalizedVel = character.AnimController.Collider.LinearVelocity == Vector2.Zero ? Vector2.Zero : Vector2.Normalize(character.AnimController.Collider.LinearVelocity); Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] - contactNormal); Hull newHull = Hull.FindHull(targetPos, null); if (newHull == null) { targetPos = ConvertUnits.ToDisplayUnits(points[0] + normalizedVel); newHull = Hull.FindHull(targetPos, null); } var gaps = newHull?.ConnectedGaps ?? Gap.GapList.Where(g => g.Submarine == submarine); targetPos = character.WorldPosition; Gap adjacentGap = Gap.FindAdjacent(gaps, targetPos, 200.0f); if (adjacentGap == null) { return(true); } if (newHull != null) { character.AnimController.FindHull(newHull.WorldPosition, true); } return(false); }