-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathArchToTileProjectile.cs
More file actions
38 lines (30 loc) · 1.25 KB
/
ArchToTileProjectile.cs
File metadata and controls
38 lines (30 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using UnityEngine;
namespace Model.Runtime.Projectiles
{
public class ArchToTileProjectile : BaseProjectile
{
private const float ProjectileSpeed = 7f;
private readonly Vector2Int _target;
private readonly float _timeToTarget;
private readonly float _totalDistance;
public ArchToTileProjectile(Unit unit, Vector2Int target, int damage, Vector2Int startPoint) : base(damage, startPoint)
{
_target = target;
_totalDistance = Vector2.Distance(StartPoint, _target);
_timeToTarget = _totalDistance / ProjectileSpeed;
}
protected override void UpdateImpl(float deltaTime, float time)
{
float timeSinceStart = time - StartTime;
float t = timeSinceStart / _timeToTarget;
Pos = Vector2.Lerp(StartPoint, _target, t);
float localHeight = 0f;
float totalDistance = _totalDistance;
float maxHeight = totalDistance * 0.6f;
localHeight = maxHeight * (-(t * 2 - 1) * (t * 2 - 1) + 1);
Height = localHeight;
if (time > StartTime + _timeToTarget)
Hit(_target);
}
}
}