@@ -6,89 +6,81 @@ function Create(self)
6
6
-- Toggle visibility of the aim area / trace to see how the detection works
7
7
self .showAim = false ;
8
8
-- Angle alteration variables (do not touch)
9
- self .rotNum = 0 ; -- Left / Right
10
- self .vertiNum = 0 ; -- Up / Down
9
+ self .rotation = 0 ; -- Left / Right movement affecting turret angle
10
+ self .verticalFactor = 0 ; -- How Up / Down movement affects turret angle
11
11
end
12
-
13
12
function Update (self )
14
-
15
- local mo = self :GetParent ();
16
- if mo and IsActor (mo ) then
13
+ local parent = self :GetParent ();
14
+ if parent and IsActor (parent ) then
17
15
18
- local parent = ToActor (mo );
19
-
20
- local ctrl = parent :GetController ();
21
-
22
- if ctrl :IsState (Controller .MOVE_RIGHT ) then
23
- self .rotNum = self .rotNum + self .turnSpeed ;
16
+ local parent = ToActor (parent );
17
+ local controller = parent :GetController ();
18
+
19
+ if controller :IsState (Controller .MOVE_RIGHT ) then
20
+ self .rotation = self .rotation + self .turnSpeed ;
24
21
end
25
- if ctrl :IsState (Controller .MOVE_LEFT ) then
26
- self .rotNum = self .rotNum - self .turnSpeed ;
22
+ if controller :IsState (Controller .MOVE_LEFT ) then
23
+ self .rotation = self .rotation - self .turnSpeed ;
27
24
end
28
25
-- Spread / tighten aim when moving up / down
29
- if ctrl :IsState (Controller .MOVE_DOWN ) then
30
- self .vertiNum = self .vertiNum - self .turnSpeed ;
26
+ if controller :IsState (Controller .MOVE_DOWN ) then
27
+ self .verticalFactor = self .verticalFactor - self .turnSpeed ;
31
28
end
32
- if math.abs (self .rotNum ) > 0.001 then
33
- self .rotNum = self .rotNum / (1 + self .turnSpeed * 2 );
29
+ if math.abs (self .rotation ) > 0.001 then
30
+ self .rotation = self .rotation / (1 + self .turnSpeed * 2 );
34
31
else
35
- self .rotNum = 0 ;
32
+ self .rotation = 0 ;
36
33
end
37
- if math.abs (self .vertiNum ) > 0.001 then
38
- self .vertiNum = self .vertiNum / (1 + self .turnSpeed * 4 );
34
+ if math.abs (self .verticalFactor ) > 0.001 then
35
+ self .verticalFactor = self .verticalFactor / (1 + self .turnSpeed * 4 );
39
36
else
40
- self .vertiNum = 0 ;
37
+ self .verticalFactor = 0 ;
41
38
end
42
39
-- Aim directly away from parent ship
43
40
local posTrace = SceneMan :ShortestDistance (parent .Pos , self .Pos , SceneMan .SceneWrapsX ):SetMagnitude (self .searchRange / 2 );
44
- self .RotAngle = (1.57 * self .vertiNum + posTrace .AbsRadAngle ) / (1 + self .vertiNum ) - self .rotNum ;
41
+ self .RotAngle = (1.57 * self .verticalFactor + posTrace .AbsRadAngle ) / (1 + self .verticalFactor ) - self .rotation ;
45
42
if self .areaMode then -- Area Mode
46
43
local aimPos = self .Pos + Vector ((self .searchRange / 2 ), 0 ):RadRotate (self .RotAngle );
47
-
48
44
-- Debug: visualize aim area
49
45
if self .showAim then
50
46
FrameMan :DrawCirclePrimitive (self .Team , aimPos , (self .searchRange / 2 ), 13 );
51
47
end
52
-
53
48
local aimTarget = MovableMan :GetClosestEnemyActor (self .Team , aimPos , (self .searchRange / 2 ), Vector ());
54
49
if aimTarget then
55
-
56
50
-- Debug: visualize search trace
57
51
if self .showAim then
58
52
FrameMan :DrawLinePrimitive (self .Team , aimPos , aimTarget .Pos , 13 );
59
53
end
60
-
61
54
-- Check that the target isn't obscured by terrain
62
55
local aimTrace = SceneMan :ShortestDistance (self .Pos , aimTarget .Pos , SceneMan .SceneWrapsX );
63
56
local terrCheck = SceneMan :CastStrengthRay (self .Pos , aimTrace , 30 , Vector (), 5 , 0 , SceneMan .SceneWrapsX );
64
-
65
57
if terrCheck == false then
66
58
self .RotAngle = aimTrace .AbsRadAngle ;
67
59
-- Debug: visualize aim trace
68
60
if self .showAim then
69
61
FrameMan :DrawLinePrimitive (self .Team , self .Pos , aimTarget .Pos , 254 );
70
62
end
71
63
self :EnableEmission (true );
72
- self :TriggerBurst (); -- Fire!
64
+ self :TriggerBurst ();
73
65
end
74
66
end
75
67
else -- Default Mode
76
68
local target ;
77
69
local aimTrace = Vector (self .searchRange , 0 ):RadRotate (self .RotAngle );
78
70
-- Search for MOs directly in line of sight of two rays
79
- local mocheck1 = SceneMan :CastMORay (self .Pos , aimTrace :RadRotate (1 / math.sqrt (self .searchRange )), parent .ID , self .Team , 0 , false , 5 );
80
- if mocheck1 ~= 255 then
81
- target = MovableMan :GetMOFromID (MovableMan :GetMOFromID (mocheck1 ).RootID );
71
+ local moCheck1 = SceneMan :CastMORay (self .Pos , aimTrace :RadRotate (1 / math.sqrt (self .searchRange )), parent .ID , self .Team , 0 , false , 5 );
72
+ if moCheck1 ~= rte . NoMOID then
73
+ target = MovableMan :GetMOFromID (MovableMan :GetMOFromID (moCheck1 ).RootID );
82
74
else
83
- local mocheck2 = SceneMan :CastMORay (self .Pos , aimTrace :RadRotate (- 1 / math.sqrt (self .searchRange )), parent .ID , self .Team , 0 , false , 5 );
84
- if mocheck2 ~= 255 then
85
- target = MovableMan :GetMOFromID (MovableMan :GetMOFromID (mocheck2 ).RootID );
75
+ local moCheck2 = SceneMan :CastMORay (self .Pos , aimTrace :RadRotate (- 1 / math.sqrt (self .searchRange )), parent .ID , self .Team , 0 , false , 5 );
76
+ if moCheck2 ~= rte . NoMOID then
77
+ target = MovableMan :GetMOFromID (MovableMan :GetMOFromID (moCheck2 ).RootID );
86
78
end
87
79
end
88
80
local color = 13 ; -- Debug trace color: red
89
81
if target and IsActor (target ) then
90
82
self :EnableEmission (true );
91
- self :TriggerBurst (); -- Fire!
83
+ self :TriggerBurst ();
92
84
93
85
if self :IsSetToBurst () then
94
86
color = 254 ; -- Debug trace color: white
0 commit comments