forked from asantee/ETHFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFollower.angelscript
51 lines (44 loc) · 1.05 KB
/
Follower.angelscript
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
39
40
41
42
43
44
45
46
47
48
49
50
51
class Follower : GameController
{
private uint m_interpStride;
private uint m_updateRate;
private vector2 m_destPos;
private PositionInterpolator@ m_interp;
private uint m_switchTime;
Follower(const vector2 &in pos, const uint interpStride = 600, const uint updateRate = 100)
{
m_interpStride = interpStride;
m_updateRate = updateRate;
@m_interp = PositionInterpolator(pos, pos, m_interpStride, true);
@(m_interp.m_filter) = @smoothEnd;
m_switchTime = 0;
}
void setDestinationPos(const vector2 &in destPos)
{
m_destPos = destPos;
}
void forcePosition(const vector2 &in pos)
{
m_interp.forcePointA(pos);
m_interp.forcePointB(pos);
}
vector2 getPos() const
{
return m_interp.getCurrentPos();
}
void reset(const vector2 &in pos)
{
m_interp.reset(pos, m_destPos, m_interpStride);
}
void draw() { }
void update()
{
if (m_interp.getCurrentPos() != m_destPos && m_switchTime > m_updateRate)
{
reset(m_interp.getCurrentPos());
m_switchTime = 0;
}
m_switchTime += GetLastFrameElapsedTime();
m_interp.update();
}
}