How can I make an aim-able cannon using motor6Ds?

Hello, I’m fairly new to the devforum and an ametuer scripter. I’m trying to make a cannon system for my pirate game.

  1. 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)

  2. 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)

  3. 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!

1 Like

Of course, you can just adjust the DesiredAngle of the motors to aim it.

2 Likes

How would I script it though? I also dont understand the property, its not changing when i change the value

1 Like

You need to increase the MaxVelocity of the motor.

2 Likes

I figured it out

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)

image

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

I’ve researched a little bit and found that Roblox doesn’t want you changing C0 on the motor6d.

While the error is suppressed, you should use the functionally identical Weld instead for this use case.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.