WASD Controls for aircraft

I’m trying to make aircraft for my group and I don’t know how to rotate the plane in terms of WASD.

I know you’re supposed to use body gyros, but how? I’m like 1/3 experienced in programming and if you could simplify your response I’d be great full.

Thanks,

– Luke

When a key is pressed down like W or S add a corresponding value like W = 1 and S = -1 for vertical rotation. So something like this

Gyro.CFrame = Gyro.CFrame * CFrame.FromEulerAnglesXYZ(Horizontal, Verticle, 0)

I don’t understand the last part of that (like why * and what does (Horizontal, Vertical, 0) mean?

  • is used as multiplication symbol for lua, so like 2 X 4 or 2 * 4.

Horizontal would correspond to the inputs. For example if A is pressed down then the Horizontal variable would = -1. Same goes for Verticle

Code example :

local UserInputService = game:GetService("UserInputService")

local Vericle = 0
local Horizontal = 0

UserInputService.InputBegan:Connect(function(InputObject, NotProccesed)
	if NotProccesed then return end
	
	if InputObject.KeyCode == Enum.KeyCode.A then
		Horizontal = math.clamp(Horizontal - 1, -1, 1)
	end
	
	if InputObject.KeyCode == Enum.KeyCode.D then
		Horizontal = math.clamp(Horizontal + 1, -1, 1)
	end
end)


UserInputService.InputEnded:Connect(function(InputObject, NotProccesed)
	if NotProccesed then return end

	if InputObject.KeyCode == Enum.KeyCode.A then
		Horizontal = math.clamp(Horizontal + 1, -1, 1)
	end

	if InputObject.KeyCode == Enum.KeyCode.D then
		Horizontal = math.clamp(Horizontal - 1, -1, 1)
	end
end)
1 Like