I am creating a test place with some tanks, and I ran into an issue with rotating the main turret…

I have seen a lot of posts here about that, however none of them solved my issue.

I have tried searching for the solution at DevHub, DevForum, Scripting Helpers…

Here’s the video describing my problem more accurately:

And here is the code that I am using right now:

function module:TurretRotate(cpos)
local rotation = CFrame.new(self.Position * Vector3.new(0,1,0),cpos) * CFrame.Angles(math.pi / 2,0,0);
self.CFrame = rotation;
end;

cpos = vector3 cursorposition

I would really like to convert that CFrame into a Vector3 value, so that I can set turret’s Orientation only, not the whole CFrame of it, but I don’t know how…

I am not very good at CFrames, so I need some help here.

function module:TurretRotate(cpos)
local unit = (cpos.Position-self.Position).Unit
local cross= unit:Cross(Vector3.new(0,1,0))
local rotation = CFrame.fromMatrix(self.Position * Vector3.new(0,1,0),cross, Vector3.new(0,1,0)) * CFrame.Angles(math.pi / 2,0,0);
self.CFrame = rotation;
end

function module:TurretRotate(cpos)
local unit = (cpos.Position-self.Position).Unit
local cross= unit:Cross(Vector3.new(0,1,0))
local rotation = CFrame.fromMatrix(self.Position,cross, Vector3.new(0,1,0)) * CFrame.Angles(math.pi ,0,0);
self.CFrame = rotation;
end

looking now, i don’t think you need to add CFrame.Angles.
try making a variable that stores the root/base of the tank

function module:TurretRotate(cpos)
local unit = (cpos.Position-self.Position).Unit
local root = self.Root-- the base, maybe idk
local cross= unit:Cross(Vector3.new(0,1,0))
local rotation = CFrame.fromMatrix((root.CFrame*CFrame.new(0,5,0)).Position,cross, root.CFrame.UpVector);
self.CFrame = rotation;
end