Hello, I’m fairly new to the devforum and an ametuer scripter. I’m trying to make a cannon system for my pirate game.
What do you want to achieve?
I want to make an aim-able cannon using motor6Ds and a vehicleseat’s throttle and steer values. I also want limits on how far you can turn the barrel. (When the player sits in the cannon seat they can use wasd to control the up/down and left/right of the barrel)
What is the issue?
I’ve already made a poorly optimized version, and I can’t figure out how to add limits to the rotation. (I don’t want the cannon barrel to be able to go too far up or down and left or right)
What solutions have you tried so far?
I’ve already tried adding a value in the script so every time you move it in a certain direction it adds +1 to it and then checks if the value is too high when you move it again.
So I’ve decided to completely overhaul it and I just need some advice and ideas to make this work. The main reason I use a cframe is because the cannon will be locked onto moving pirate ship via bodyvelocity so the rotation method cant affect the ship. Thanks!
I added a vehicleseat and added a script that checks for throttle changes, then changes the orientation of the Motor6D.
Heres the code if anybodys wondering:
local VehicleSeat = script.Parent
VehicleSeat.Changed:Connect(function(property)
if property == "Steer" then
if VehicleSeat.Steer == -1 then
local currentCFrame = script.Parent.Parent.Base.Motor6D.C0
local newRotation = CFrame.Angles(0, math.rad(10), 0) * currentCFrame
script.Parent.Parent.Base.Motor6D.C0 = newRotation
elseif VehicleSeat.Steer == 1 then
local currentCFrame = script.Parent.Parent.Base.Motor6D.C0
local newRotation = CFrame.Angles(0, math.rad(-10), 0) * currentCFrame
script.Parent.Parent.Base.Motor6D.C0 = newRotation
end
elseif property == "Throttle" then
if VehicleSeat.Throttle == 1 then
local currentCFrame = script.Parent.Parent.BasePivot.Motor6D.C0
local newRotation = CFrame.Angles(0, 0, math.rad(10)) * currentCFrame
script.Parent.Parent.BasePivot.Motor6D.C0 = newRotation
elseif VehicleSeat.Throttle == -1 then
local currentCFrame = script.Parent.Parent.BasePivot.Motor6D.C0
local newRotation = CFrame.Angles(0, 0, math.rad(-10)) * currentCFrame
script.Parent.Parent.BasePivot.Motor6D.C0 = newRotation
end
end
end)
Im still working on the limits but thats easy all I need to do is keep track of every time the player changes throttle or steer then check that number every time it moves