private void OnPosition(AimPositionEvent gameEvent) { transform.position = gameEvent.position; snapToGrid.AdjustToGrid(); transform.position += Vector3.back; EnableOverlays(true); }
private void GeneratePoints() { Vector3 origin = transform.position; var config = GlobalState.Instance.Config; int index = 0; var distance = aimlineConfig.length - config.bubbles.size; var direction = (aimTarget - origin); var shooterRadius = config.bubbles.size * config.bubbles.shotColliderScale; int reflections = settings.Value.maxReflections; direction.z = 0.0f; direction.Normalize(); points.Clear(); points.Add(origin + config.bubbles.size * direction * 2.0f); while (distance > 0.0f) { var hit = Physics2D.CircleCast(points[index], shooterRadius, direction, distance, LAYER_MASK); if (hit.collider != null) { if (Vector3.Dot(direction, ((Vector3)hit.point - points[index])) < 0.0f) { // Make sure we're not trying to go backwards break; } distance = hit.distance - shooterRadius * 0.5f; if (hit.collider.gameObject.tag == StringConstants.Tags.BUBBLES) { // Push the aimline endpoint up against the edge of the bubble we collided with distance += shooterRadius; } } if ((hit.collider != null) && (reflections > 0) && (hit.collider.gameObject.tag != StringConstants.Tags.BUBBLES)) { // We've hit a wall points.Add(CalculateReflectionPoint(points[index], direction, distance)); --reflections; index++; // Make sure we shouldn't have hit a bubble as we bounce off the wall. This should resolve the edge // case that allowed aiming around the end of a short row. if (Physics2D.OverlapCircle(points[index], config.bubbles.size / 2.0f, GAME_OBJECT_MASK) != null) { points[index] = points[index] - direction * config.bubbles.size / 2.0f; break; } distance = settings.Value.reflectionDistance; direction = new Vector2(-direction.x, direction.y); continue; } points.Add(points[index] + distance * direction); break; } points[0] = origin; AimPositionEvent.Dispatch(points[points.Count - 1]); }