Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 9754d0d

Browse files
committed
Turret attachable now supports any MO as opposed to actors only
1 parent b5518d5 commit 9754d0d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

Base.rte/Craft/Shared/MGTurret.lua

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ function Create(self)
1111
end
1212
function Update(self)
1313
local parent = self:GetParent();
14-
if parent and IsActor(parent) then
15-
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;
21-
end
22-
if controller:IsState(Controller.MOVE_LEFT) then
23-
self.rotation = self.rotation - self.turnSpeed;
24-
end
25-
-- Spread / tighten aim when moving up / down
26-
if controller:IsState(Controller.MOVE_DOWN) then
27-
self.verticalFactor = self.verticalFactor - self.turnSpeed;
14+
if parent then
15+
if IsActor(parent) then
16+
parent = ToActor(parent);
17+
local controller = parent:GetController();
18+
19+
if controller:IsState(Controller.MOVE_RIGHT) then
20+
self.rotation = self.rotation + self.turnSpeed;
21+
end
22+
if controller:IsState(Controller.MOVE_LEFT) then
23+
self.rotation = self.rotation - self.turnSpeed;
24+
end
25+
-- Spread / tighten aim when moving up / down
26+
if controller:IsState(Controller.MOVE_DOWN) then
27+
self.verticalFactor = self.verticalFactor - self.turnSpeed;
28+
end
2829
end
2930
if math.abs(self.rotation) > 0.001 then
3031
self.rotation = self.rotation / (1 + self.turnSpeed * 2);
@@ -36,9 +37,9 @@ function Update(self)
3637
else
3738
self.verticalFactor = 0;
3839
end
39-
-- Aim directly away from parent ship
40+
-- Aim directly away from parent
4041
local posTrace = SceneMan:ShortestDistance(parent.Pos, self.Pos, SceneMan.SceneWrapsX):SetMagnitude(self.searchRange / 2);
41-
self.RotAngle = (1.57 * self.verticalFactor + posTrace.AbsRadAngle) / (1 + self.verticalFactor) - self.rotation;
42+
self.RotAngle = (1.57 * self.verticalFactor + posTrace.AbsRadAngle + (parent.HFlipped and math.pi or 0)) / (1 + self.verticalFactor) - self.rotation;
4243
if self.areaMode then -- Area Mode
4344
local aimPos = self.Pos + Vector((self.searchRange / 2), 0):RadRotate(self.RotAngle);
4445
-- Debug: visualize aim area

0 commit comments

Comments
 (0)