I want to make a script that makes the “tower” only rotate on the y axis. With the code I have now it almost works, but it rotates 90 degrees each time. This is the code
while distance < 10 and attacked == false do
local ACF = enemies.CFrame
local CRX, CRY = ACF:ToOrientation()
script.Parent.Top.CFrame = CFrame.new(script.Parent.Top.Position) * CFrame.fromOrientation(CRX, CRY, 0)
Here’s an example for the character rotating to face the mouse:
local P = game:GetService('Players')
local p = P.LocalPlayer
local m = p:GetMouse()
local c = p.Character
local root = c:WaitForChild('HumanoidRootPart')
m.Move:Connect(function()
local x,y,z = CFrame.new(root.Position,m.Hit.Position):ToOrientation()
root.CFrame = CFrame.new(root.Position)*CFrame.fromOrientation(0,y,z)
end)
This might make things easier in the future:
function OrientationFromCFrame(cframe)
return Vector3.new(cframe:ToOrientation())
end
Example using function:
function OrientationFromCFrame(cframe)
return Vector3.new(cframe:ToOrientation())
end
local P = game:GetService('Players')
local p = P.LocalPlayer
local m = p:GetMouse()
local c = p.Character
local root = c:WaitForChild('HumanoidRootPart')
local cam = workspace.CurrentCamera
cam.CameraSubject = c:WaitForChild('Head')
m.Move:Connect(function()
local rot = OrientationFromCFrame(CFrame.new(root.Position,m.Hit.Position))
root.CFrame = CFrame.new(root.Position)*CFrame.fromOrientation(0,rot.Y,rot.Z)
end)
2 Likes
yes you can. Just set axis you want to lock to number you want to set.
sorry for not responding… but yes that worked!
2 Likes