Hi, currently I’m working on making a system where you fire cannons on a ship on whichever side your camera is closest towards facing. For example, if your camera was oriented to the left of your ship, it’d fire the cannons on the left side. The base concept looks like this:
The highlighted part would be the side that the ship’s cannons would fire on if you were to fire.
This is the code that I have so far for it, where it’s implied that the direction the ship’s pointing at is always an orientation of (0,0,0):
game.Workspace.CurrentCamera.Changed:connect(function()
game.Workspace.CamPart.CFrame = game.Workspace.CurrentCamera.CFrame
local Dir = game.Workspace.CamPart.Orientation.Y
game.Workspace.Forward.BrickColor = BrickColor.new("Medium stone grey")
game.Workspace.Right.BrickColor = BrickColor.new("Medium stone grey")
game.Workspace.Left.BrickColor = BrickColor.new("Medium stone grey")
game.Workspace.Backward.BrickColor = BrickColor.new("Medium stone grey")
if (Dir >= 0 and Dir <= 45) or (Dir <= 0 and Dir >= -45) then -- Forward
game.Workspace.Forward.BrickColor = BrickColor.new("Lime green")
elseif (Dir >= 45 and Dir <= 135) then -- Left
game.Workspace.Left.BrickColor = BrickColor.new("Lime green")
elseif (Dir <= -45 and Dir >= -135) then -- Right
game.Workspace.Right.BrickColor = BrickColor.new("Lime green")
elseif (Dir >= 135 and Dir <= 180) or (Dir <= -135 and Dir >= -180) then -- Backwards
game.Workspace.Backward.BrickColor = BrickColor.new("Lime green")
end
end)
But naturally a ship has the ability to turn, and with how this code is written, the side that is chosen depends on the camera’s orientation alone, not the camera’s orientation in relation to the ship’s. So when the ship turns, say 90 degrees, this happens:
The issue is that I’m not sure how to make the camera select a side based on the camera’s orientation in relation to the ship’s, and not the camera’s orientation alone. How do I do this?
Thanks.