Hey guys this is pretty much my first post on here. i am trying to make a kind of like ac4 black flag ship movement it is going pretty well but when i rotate the cannons they seem to move faster the more i use them does anyone see the mistake i am making and knows a solution.
task.wait()
local CameraModule = {}
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local RunService = game:GetService(“RunService”)
local camera = game.Workspace.CurrentCamera
local uis = game:GetService(“UserInputService”)
local maxVerticalRotation = 45
local maxHorizontalRotation = 45
local rightCam = character:WaitForChild(“Cameras”).RightCam
local leftCam = character:WaitForChild(“Cameras”).LeftCam
local Cannons = character:WaitForChild(“Ship”).Cannons
local RightCan = Cannons.Right:GetChildren()
local LeftCan = Cannons.Left:GetChildren()
local initialCFrame = {}
for _, Cannon in ipairs(RightCan) do
local motorbarrel = Cannon.Barrel:FindFirstChildOfClass(“Motor6D”)
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbarrel then initialCFrame[motorbarrel] = motorbarrel.C0 end
if motorbase then initialCFrame[motorbase] = motorbase.C0 end
end
for _, Cannon in ipairs(LeftCan) do
local motorbarrel = Cannon.Barrel:FindFirstChildOfClass(“Motor6D”)
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbarrel then initialCFrame[motorbarrel] = motorbarrel.C0 end
if motorbase then initialCFrame[motorbase] = motorbase.C0 end
end
local currentRotation = {}
for _, Cannon in ipairs(RightCan) do
local motorbarrel = Cannon.Barrel:FindFirstChild(“OfClassMotor6D”)
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbarrel then initialCFrame[motorbarrel] = motorbarrel.C0 currentRotation[motorbarrel] = 0 end
if motorbase then initialCFrame[motorbase] = motorbase.C0 currentRotation[motorbase] = 0 end
end
for _, Cannon in ipairs(LeftCan) do
local motorbarrel = Cannon.Barrel:FindFirstChild(“OfClassMotor6D”)
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbarrel then initialCFrame[motorbarrel] = motorbarrel.C0 currentRotation[motorbarrel] = 0 end
if motorbase then initialCFrame[motorbase] = motorbase.C0 currentRotation[motorbase] = 0 end
end
local connection
local rightCamOn = false
local leftCamOn = false
local CannonBall = Cannons.CannonBall
local Debris = game:GetService(“Debris”)
local function fireCannon(cannon)
local newcannonball = CannonBall:Clone()
local offset = Vector3.new(0, 0, -5)
newcannonball.Parent = Cannons.ShotBalls
newcannonball.WeldConstraint:Destroy()
newcannonball.CFrame = cannon.Barrel.CFrame * CFrame.new(offset)
newcannonball.Transparency = 0
local force = Instance.new(“BodyVelocity”)
force.Velocity = cannon.Barrel.CFrame.LookVector * 100
force.Parent = newcannonball
local despawnTime = 5
Debris:AddItem(newcannonball, despawnTime)
end
function CameraModule.lookRightOn()
if connection then connection:Disconnect() end
connection = RunService.RenderStepped:Connect(function()
rightCamOn = true
camera.CFrame = rightCam.CFrame
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) and rightCamOn == true then
uis.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and rightCamOn == true then
for _, Cannon in ipairs(RightCan) do
local motorbarrel = Cannon.Barrel:FindFirstChildOfClass(“Motor6D”)
if motorbarrel then
local newRotationY = input.Delta.Y * 0.01
currentRotation[motorbarrel] = math.clamp((currentRotation[motorbarrel]) + newRotationY, -maxVerticalRotation, maxVerticalRotation)
motorbarrel.C0 = initialCFrame[motorbarrel] * CFrame.Angles(math.rad(currentRotation[motorbarrel]), 0, 0)
end
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbase then
local newRotationX = input.Delta.X * 0.01
currentRotation[motorbase] = math.clamp((currentRotation[motorbase]) + newRotationX, -maxHorizontalRotation, maxHorizontalRotation)
motorbase.C0 = initialCFrame[motorbase] * CFrame.Angles(0, math.rad(currentRotation[motorbase]), 0)
end
end
end
end)
end
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) and rightCamOn == true then
for i, cannon in ipairs(RightCan) do
fireCannon(cannon)
end
end
end)
end
function CameraModule.lookLeftOn()
if connection then connection:Disconnect() end
connection = RunService.RenderStepped:Connect(function()
leftCamOn = true
camera.CFrame = leftCam.CFrame
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) and leftCamOn == true then
uis.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and leftCamOn == true then
for _, Cannon in ipairs(LeftCan) do
local motorbarrel = Cannon.Barrel:FindFirstChildOfClass(“Motor6D”)
if motorbarrel then
local newRotationY = input.Delta.Y * 0.01
currentRotation[motorbarrel] = math.clamp((currentRotation[motorbarrel]) + newRotationY, -maxVerticalRotation, maxVerticalRotation)
motorbarrel.C0 = initialCFrame[motorbarrel] * CFrame.Angles(math.rad(currentRotation[motorbarrel]), 0, 0)
end
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbase then
local newRotationX = input.Delta.X * 0.01
currentRotation[motorbase] = math.clamp((currentRotation[motorbase]) + newRotationX, -maxHorizontalRotation, maxHorizontalRotation)
motorbase.C0 = initialCFrame[motorbase] * CFrame.Angles(0, math.rad(currentRotation[motorbase]), 0)
end
end
end
end)
end
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) and leftCamOn == true then
for i, cannon in ipairs(LeftCan) do
fireCannon(cannon)
end
end
end)
end
function CameraModule.lookNatural()
if connection then connection:Disconnect() end
uis.MouseIconEnabled = false
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
rightCamOn = false
leftCamOn = false
for _, Cannon in ipairs(RightCan) do
local motorbarrel = Cannon.Barrel:FindFirstChildOfClass(“Motor6D”)
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbarrel and initialCFrame[motorbarrel] then motorbarrel.C0 = initialCFrame[motorbarrel] end
if motorbase and initialCFrame[motorbase] then motorbase.C0 = initialCFrame[motorbase] end
if motorbarrel then initialCFrame[motorbarrel] = motorbarrel.C0 currentRotation[motorbarrel] = 0 end
if motorbase then initialCFrame[motorbase] = motorbase.C0 currentRotation[motorbase] = 0 end
if motorbarrel then
initialCFrame[motorbarrel] = motorbarrel.C0
currentRotation[motorbarrel] = 0
end
end
for _, Cannon in ipairs(LeftCan) do
local motorbarrel = Cannon.Barrel:FindFirstChildOfClass(“Motor6D”)
local motorbase = Cannon.Base:FindFirstChildOfClass(“Motor6D”)
if motorbarrel and initialCFrame[motorbarrel] then motorbarrel.C0 = initialCFrame[motorbarrel] end
if motorbase and initialCFrame[motorbase] then motorbase.C0 = initialCFrame[motorbase] end
if motorbarrel then initialCFrame[motorbarrel] = motorbarrel.C0 currentRotation[motorbarrel] = 0 end
if motorbase then initialCFrame[motorbase] = motorbase.C0 currentRotation[motorbase] = 0 end
if motorbarrel then
initialCFrame[motorbarrel] = motorbarrel.C0
currentRotation[motorbarrel] = 0
end
end
end
return CameraModule
https://cdn.discordapp.com/attachments/547473581458849792/1173663109622272170/Animation.gif?ex=6564c5f2&is=655250f2&hm=60c4ecf3ebfc9086be3636a65158105227a4799816ae8e6dbf0d6b58d6168117& for a gif very professional