Turret Aiming problem

so i want to make the barrel to rotate around the cylinder to face the target, just like this.

The problem is, I dont know how to do it. this turret is not like other turret where the barrel itself can rotate freely. I want to make it so that the turret can only aim 180 degrees vertically and 360 degrees horizontally (by the base, which is the dark gray part). i cant find any sources regarding this type of turret.

Hopefully this is enough information for you to help me.


I no idea about its will work or not. But you can try TurretPart.z.CFrame.LookAt(Target)


Well, that line of code is kind of obvious to not work, but I try it anyway. it just says that " Z is not a valid member of Part".


Don’t CFrame the part, use welds or motor6d’s.


how do i do it with welds or motor6d? I tried using the following code

UDR.CFrame = CFrame.new(UDR.Position, target.Position)

and it didnt move a bit. UDR being the cylinder part that is hidden by the bigger cylinder part. I connected it to the barrel.


My turret controller has the constraints you are looking for.


i have question regarding

local GunHead = TurretController.new(ModelMotor6Ds["GunHead"],gunHeadConstraints)

i dont really understand what the placeholders mean (like ModelMotor6Ds, gunHeadConstraints).

ModelMotor6Ds is just a table. ModelMotor6Ds.GunHead is the Motor6D instance within the table.

gunHeadConstraints is a dictionary of the turret settings

local gunHeadConstraints = {
	["YawLeft"] = 89; -- 0 to 180
	["YawRight"] = 89; -- 0 to 180
	["ElevationAngle"] = 0; -- 0 to 90
	["DepressionAngle"] = 0; -- 0 to 90 I believe haven't tested much

Yaw is the Y axis rotation.

Elevation and depression angles will be the pitch angles.

1 Like

The simplest way of doing this, is to put a BodyGyro in the turret and connect the turret’s Parts using constraints, and using RunService, you make the turret face the Part.

just to make sure it the right part, which part do i put the bodygyro to?
(red marked part is the barrel, and blue marked part is the rotation part, which i use it to rotate the barrel. the dark gray part is where i yaw the entire part on top of it)

The problem with body gyro is that if the parts can collide then sometimes it won’t rotate.

Put the BodyGyro, In the part that you want to rotate.

The method I said works flawlessly, I have already made turrets multiple times…

Here is one example of a turret I made:

I wouldn’t call it “flawless”. Body movers generally aren’t very consistent in large and detailed games. In that game I could clearly see delay between movements and occasional lags.

That is due, either to your client or RunService.

The game is literally non intense how is it my client’s fault? If it flaws that easily then could you really call it flawless?

Can you please provide evidence of your claims.

Yeah play your own game then you will see it.

i have a wifi with 500 mbps and im getting so long delay :frowning:

What do you mean delay? I’m not having any lag problems with it…