internal void Initialize(Projectile projectile) { Element[] projectileElements = projectile.elements.ToArray(); damage = ElementUtility.ProjectileDamage(projectileElements); bouncesLeft = ElementUtility.Bounces(projectileElements); chainLength = ElementUtility.ChainLength(projectileElements); speed = ElementUtility.ProjectileSpeed(projectileElements); AOEDamageDealer = new AOEDamageDealer(ElementUtility.AoE(projectileElements) * projectile.areaOfEffectMultiplier, transform, projectile.elements); primaryMovementType = ElementUtility.Movement(projectile.elements.Peek()); this.projectile = projectile; switch (primaryMovementType) { case ProjectileMovementType.BounceOnGround: Parabola[] parabolas = ParabolaCalculator.CalculateFullTrajectory(transform.position, projectile.target.position, ElementUtility.ProjectileSpeed(projectileElements), transform.position.y, 0, bouncesLeft); projectileMover = new ProjectileMover(transform, parabolas, ElementUtility.ProjectileSpeed(projectile.elements.ToArray()) * projectile.speedMultiplier); break; case ProjectileMovementType.StraightChain: projectileMover = new ProjectileMover(transform, projectile.target, ElementUtility.ProjectileSpeed(projectile.elements.ToArray()) * projectile.speedMultiplier); break; case ProjectileMovementType.AOEAtTower: projectileMover = new ProjectileMover(projectile.speedMultiplier * speed, 0, transform); OnAOEAtTowerActivation(); break; } }
private void DisplayParabola(DisplayParabolaRequestEvent obj) { currentRequest = obj; currentRequest.speed = speed; currentRequest.arcHeight = arcHeight; currentRequest.xReductionPerBounce = xReductionPerBounce; currentRequest.bounces = bounces; if (projectileOrigin != obj.projectileOrigin) { projectileOrigin = obj.projectileOrigin; } if (obj.variableTarget != null) { target = obj.variableTarget; obj.target = target.position; } startingPos = projectileOrigin.position; lineRenderer.enabled = true; lineRenderer.positionCount = 0; Parabola[] parabolas = ParabolaCalculator.CalculateFullTrajectory(obj); lineRenderer.positionCount = ParabolaCalculator.PointAmountInParabolaArray(parabolas); int pointIndexInLineRenderer = 0; for (int parabolaIndex = 0; parabolaIndex < parabolas.Length; parabolaIndex++) { for (int pointIndex = 0; pointIndex < parabolas[parabolaIndex].points.Count; pointIndex++) { lineRenderer.SetPosition(pointIndexInLineRenderer, parabolas[parabolaIndex].points[pointIndex]); pointIndexInLineRenderer++; } } target.hasChanged = false; }
private void CheckBouncesLeft() { if (bouncesLeft <= 0) { Destroy(gameObject); } else { Vector3 bounceTargetPosition = transform.position + transform.forward * 2f; bounceTargetPosition.y = 0; bounceTargetPosition.x += 0.1f; Parabola[] parabolas = ParabolaCalculator.CalculateFullTrajectory(transform.position, bounceTargetPosition, ElementUtility.ProjectileSpeed(projectile.elements.ToArray()), transform.position.y + 1f, 0, bouncesLeft); projectileMover.SetParabolas(parabolas); primaryMovementType = ProjectileMovementType.BounceOnGround; } }