Can someone explain this please (Helicopter)

I found this script inside a helicopter model. I want to make my own helicopter, but I want to understand how to make one rather than copying scripts. This was the only script inside a helicopter model. Could someone tell me how this works?


local inputS=game:getService("UserInputService")
local player=game.Players.LocalPlayer
local engine=script.Parent.Engine
local rotor1=script.Parent.Motor
local rotor2=script.Parent.Rotor

local gyro=Instance.new("BodyGyro",engine)
gyro.maxTorque=Vector3.new(1e4,1e4,1e4)
gyro.D=1250
gyro.cframe=engine.CFrame

local spd=Instance.new("BodyVelocity",engine)
spd.maxForce=Vector3.new(1e9,1e9,1e9)
local max_speed=50

local w,a,s,d,up,dn

inputS.InputBegan:connect(function(input)
	local code=input.KeyCode
	if code==Enum.KeyCode.W or code==Enum.KeyCode.Up then
		w=true
	elseif code==Enum.KeyCode.A or code==Enum.KeyCode.Left then
		a=true
	elseif code==Enum.KeyCode.S or code==Enum.KeyCode.Down then
		s=true
	elseif code==Enum.KeyCode.D or code==Enum.KeyCode.Right then
		d=true
	elseif code==Enum.KeyCode.LeftShift then
		up=true
	elseif input.KeyCode==Enum.KeyCode.LeftControl then
		dn=true
	end
end)

inputS.InputEnded:connect(function(input)
	local code=input.KeyCode
	if code==Enum.KeyCode.W or code==Enum.KeyCode.Up then
		w=false
	elseif code==Enum.KeyCode.A or code==Enum.KeyCode.Left then
		a=false
	elseif code==Enum.KeyCode.S or code==Enum.KeyCode.Down then
		s=false
	elseif code==Enum.KeyCode.D or code==Enum.KeyCode.Right then
		d=false
	elseif code==Enum.KeyCode.LeftShift then
		up=false
	elseif input.KeyCode==Enum.KeyCode.LeftControl then
		dn=false
	end
end)

function rotorSpd(spd)
	rotor1.TopParamA=-spd
	rotor1.TopParamB=spd
	rotor2.BottomParamA=-spd
	rotor2.BottomParamB=spd
end

local chg=Vector3.new(0,0,0)
local rot=0
local inc=0
while true do
	wait(.1)
	local lv=engine.CFrame.lookVector
	if up then
		rotorSpd(0.6)
		if chg.y<30 then
			chg=chg+Vector3.new(0,2,0)
		end
	elseif dn then
		rotorSpd(0.2)
		if chg.y>-30 then
			chg=chg+Vector3.new(0,-2,0)
		end
	elseif chg.magnitude>1 then
		rotorSpd(0.4)
		chg=chg*0.9
	else
		rotorSpd(0.4)
		chg=Vector3.new(0,1,0)
	end
	if w then
		if inc<max_speed then
			inc=inc+2
		end
		spd.velocity=chg+(engine.CFrame.lookVector+Vector3.new(0,0.3,0))*inc
		gyro.cframe=CFrame.new(engine.Position,engine.Position+Vector3.new(lv.x,-0.3,lv.z))
	elseif s then
		if inc >-max_speed then
			inc=inc-2
		end
		spd.velocity=chg+(engine.CFrame.lookVector-Vector3.new(0,0.3,0))*inc
		gyro.cframe=CFrame.new(engine.Position,engine.Position+Vector3.new(lv.x,0.3,lv.z))
	else
		inc=inc*0.9
		spd.velocity=chg+engine.CFrame.lookVector*inc+Vector3.new(0,2,0)
		gyro.cframe=CFrame.new(engine.Position,engine.Position+Vector3.new(lv.x,0,lv.z))
	end

	if a then
		if rot<math.pi/8 then
			rot=rot+math.pi/20
		end
		gyro.cframe=gyro.cframe*CFrame.Angles(0,math.pi/10,rot)
	elseif d then
		if rot>-math.pi/8 then
			rot=rot-math.pi/20
		end
		gyro.cframe=gyro.cframe*CFrame.Angles(0,-math.pi/10,rot)
	else
		rot=0
	end
end
1 Like

What is the first line of the code, which you don’t understand?

Are you asking about scripting or about helicopter physics?

This script uses Roblox’s legacy BodyMovers in order to simulate VTOL (vertical take off and landing) for a helicopter.

It does this by producing a thrust which lifts it up and using a gyro to provide rotational movement.

There’s a lot to unpack from this script and I would 100% look into the physics of aircraft (specifically VTOLs) and how they work.

Here is a brief and simplified explanation of how they work in the real world:
In order to lift off the ground the rotating blades (main rotor) atop the helicopter must produce a force greater than the weight of the craft, this is called “Lift”. As we should be aware, helicopters can also hover, this happens when Lift = Weight (+External forces, like drag).

Lift is produced through the blades rotating and pushing air downwards, creating a lift force upwards (see: newton’s third law) countering the weight of the craft.

Thrust is produced by the main rotor tilting forward, rearward, or sidewards.

Helicopters also have a rear blade (tail rotor) which stabilises the craft by producing a counter force to nullify the torque produced by the main rotor; it also serves a purpose in rotating the craft around the vertical axis.

Finally, I will end with the lift equation:

L = C Ă— ((p Ă— v^2)Ă·2) Ă— S

C = Coefficient of Lift, this is equated from the wings angle of attack and the wing shape itself. There are other variables at play but that’s the simple explanation.
p = Air density
v = velocity
S = wing surface area

I intentionally didn’t mention drag and other variables in order to try and keep this short and simple, hopefully I achieved one of those while also maintaining accuracy, if anyone sees anything explained incorrectly feel free to correct me it has been awhile since I’ve dabbled in aircraft physics.

5 Likes