Rotating a helicopter forwards (Model)

Making a helicopter that when you move your mouse downwards it will rotate your helicopter forward
like this:

image

I’m trying to get the last angle so I can add onto it. Sorry it’s a bit hard to explain.

Error: Angles is not a valid member of CFrame

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local minicopter = game.Workspace:WaitForChild("Minicopter")
local force = minicopter:WaitForChild("Main"):WaitForChild("Force")
local reject = minicopter:WaitForChild("Main"):WaitForChild("Reject")

wait(6)

while true do
	local last = camera.CFrame.LookVector.Y
	wait()
	if last > camera.CFrame.LookVector.Y then
		print("looking down")
		local ox = minicopter.PrimaryPart.Orientation.X
		local oy = minicopter.PrimaryPart.Orientation.Y
		local oz = minicopter.PrimaryPart.Orientation.Z
		print(oz)
		if oz > -45 and oz < 45 then
			local last2 = minicopter.PrimaryPart.CFrame.Angles.Z
			print(last2)
			minicopter:SetPrimaryPartCFrame(minicopter.PrimaryPart.CFrame*CFrame.Angles(0, 0, math.rad(last2 +0.01)))
		end
	end
end
1 Like

Rotating a CFrame

and more detail on rotation:

CFrame.Angles() is a method you can call with parameters (or arguments), not a property to set or assigned a value to. When you call CFrame.Angles(), it will set the appropriate rotation / orientation values inside the CFrame matrix (it does the math).

It look likes you want to work in degrees. The parameters passed to CFrame.Angles() need to be converted to radians using math.rad(degrees).

In radians:

math.pi = 180 degrees
math.pi/2 = 90 degrees

local radianValue = math.rad(45) -- convert 45 degrees to radians
print(radianValue) 
print(math.pi/4)

Say you want to rotate the model 5 degrees by setting your PrimaryPart.CFrame:

-- Create new CFrame to rotate by
local rotateCFrame = CFrame.Angles(0, 0, math.rad(5)) -- rotate by 5 degrees around the Z axis

-- Rotate PrimaryPart current CFrame by rotateCFrame amount
minicomputer.PrimaryPart.CFrame = minicomputer.PrimaryPart.CFrame * rotateCFrame

Some other points:

  • You may want to Tween the CFrame for a smooth transitional movement between the level orientation and the nose down orientation.
  • You may want to incorporate Mouse.Hit and use CFrame.new(currentPosition, lookAtPosition) to face the model towards the mouse.
  • Avoid SetPrimaryCFrame, use other CFrame methods or set the value of PrimaryPart.CFrame instead.
  • All the best and have fun
3 Likes