private void ThrowRayCast(Vector2 from, Vector2 direction, float distance, Vector2 raycastvector) { RaycastHit2D hit = Physics2D.Raycast(from, direction, distance, layers); hitInfo hitInformation; Debug.DrawLine(from, direction * distance + from, Color.red * (1 - colorauxIterator / Angle)); if (hit) { raycastvector = new Vector2(hit.point.x, hit.point.y); } hitInformation = new hitInfo(true, raycastvector, hit.collider); hitsList.Add(hitInformation); }
private void determineVisiblePoints() { hitInfo currentHitinfo, lastHitInfo = hitsList[0]; Vector2 firstCollision = lastHitInfo.pointOfCollision; Vector2[] currentColliderVertices; VisibleConePoints.AddFirst(firstCollision); LinkedListNode <Vector2> currentpoint; LinkedListNode <Vector2> previouspoint; Collider2D colliderBetweenpoints = new Collider2D(); for (int i = 1; i < hitsList.Count; i++) { currentHitinfo = hitsList[i]; currentpoint = VisibleConePoints.AddLast(lastHitInfo.pointOfCollision); //si uno de los dos if (lastHitInfo.collisionCollider != currentHitinfo.collisionCollider) { if (currentpoint.Previous != null) { previouspoint = currentpoint.Previous; colliderBetweenpoints = currentHitinfo.collisionCollider == null ? lastHitInfo.collisionCollider : currentHitinfo.collisionCollider; } } else { Vector2 direction = currentHitinfo.pointOfCollision - lastHitInfo.pointOfCollision; RaycastHit2D hit = Physics2D.Raycast(lastHitInfo.pointOfCollision, direction.normalized, direction.magnitude, layers); if (hit) { colliderBetweenpoints = hit.collider; } } if (colliderBetweenpoints != null) { currentColliderVertices = colliderBetweenpoints.gameObject.GetComponent <SpriteRenderer>().sprite.vertices; addVertexInTriangle(currentColliderVertices, colliderBetweenpoints, lastHitInfo, currentHitinfo, currentpoint); } lastHitInfo = currentHitinfo; } VisibleConePoints.AddLast(hitsList[hitsList.Count - 1].pointOfCollision); }
void Start() { info = new hitInfo(); }
private void addVertexInTriangle(Vector2[] currentColliderVertices, Collider2D colliderBetweenpoints, hitInfo lastHitInfo, hitInfo currentHitinfo, LinkedListNode <Vector2> currentpoint) { foreach (var vertex in currentColliderVertices) { Vector2 vertPosition = (Vector2)colliderBetweenpoints.gameObject.transform.position + vertex; if (isInTriangleABC(vertPosition, lastHitInfo.pointOfCollision, currentHitinfo.pointOfCollision, source)) { VisibleConePoints.AddAfter(currentpoint, vertPosition); } } }
/// <summary> /// Calculates damage to shields, armor, and character given damage and a character model /// </summary> public static (float damageToShields, float damageToArmor, float damageToCharacter) DamageRatio(ActorHitInfo hitInfo, CharacterModel character) => DamageRatioImpl(hitInfo, character);