How do I improve my Aircraft? Can someone explain how CFrame.fromEulerAnglesXYZ works with this?

I have never scripted any form of aircraft or vehicle before. I’ve been searching through forums and I found a few ways of making an aircraft fly. The only issue is the aircraft is not what I want, right now it’s more of a bouncing ping pong ball to say the least. Strange functionality. I have looked into some free model airplanes seeing how they’re scripted and they all include something about CFrame.fromEulerAnglesXYZ. Could someone give me a clear and simple explanation of what it does and how I can make my aircraft less of a Bouncing Saucer? Thanks!

  • SCRIPT
   
local rs = game:GetService("RunService")

local VehiclePrompt = script.Parent.EnterVehiclePrompt

local Occupied = script.Parent.Occupied

local Occupant = script.Parent.Occupant

local AircraftCamera = script.Parent.AircraftCamera

local AircraftEventFolder = game.ReplicatedStorage:FindFirstChild("Aircrafts")

local TemporaryCell = game.Workspace.AircraftEntryCharacterPlacement

local Events = {

	["Enter"] = AircraftEventFolder:FindFirstChild("Enter")

}

local VehicleSeat = script.Parent.VehicleSeat

local BG = VehicleSeat.BodyGyro

local BGDefault = BG.Default

local BP = VehicleSeat.BodyPosition

local BPDefault = BP.Default

local BV = VehicleSeat.BodyVelocity

local BVDefault = BV.Default

local maxspeed = VehicleSeat.MaxSpeed

maxspeed = 200

local value1 = 0

BG.CFrame = VehicleSeat.CFrame

BP.Position = VehicleSeat.Position

VehiclePrompt.Triggered:Connect(function(player)

	Events.Enter:FireClient(player,AircraftCamera)

	local Char = player.Character

	local HRP = Char.HumanoidRootPart

	local Humanoid = Char.Humanoid

	wait(1)

	Humanoid.JumpPower = 0

	VehicleSeat:Sit(Humanoid)

	BG.MaxTorque = BGDefault.Value

	BP.MaxForce = BPDefault.Value

	Occupied.Value = true

	Occupant.Value = player.Name

	while Occupied.Value == true do

		wait()

		if VehicleSeat.Throttle == 1 then
			if value1 < maxspeed then value1 = value1 + 1 end
			BV.velocity = VehicleSeat.CFrame.lookVector * value1
		end

		if VehicleSeat.Throttle == 0 then
			value1 = 0
			BV.velocity = VehicleSeat.CFrame.lookVector * value1
		end

		if VehicleSeat.Throttle == -1 then
			if VehicleSeat.Steer == -1 then
				BP.Position = VehicleSeat.CFrame * Vector3.new(0,10,0)
			end
		end

		if VehicleSeat.Throttle == -1 then
			if VehicleSeat.Steer == 0 then
				BP.Position = VehicleSeat.CFrame * Vector3.new(0,-10,0)
			end
		end

		if VehicleSeat.Steer == 1 then
			BG.CFrame = BG.CFrame * CFrame.fromEulerAnglesXYZ(0,-.1,0)
		end

		if VehicleSeat.Steer == -1 then
			if VehicleSeat.Throttle == 0 or VehicleSeat.Throttle == 1 then
				BG.CFrame = BG.CFrame * CFrame.fromEulerAnglesXYZ(0,.1,0)
			end
		end

	end

end)


Occupied.Changed:Connect(function()

	if Occupied.Value == true then

		VehiclePrompt.Enabled = false

	elseif Occupied.Value == false then

		VehiclePrompt.Enabled = true

	end

end)
  • LOCAL SCRIPT
    
local TS = game:GetService("TweenService")

local AircraftEventFolder = game.ReplicatedStorage:FindFirstChild("Aircrafts")

local Cam = workspace.CurrentCamera

local Events = {

	["Enter"] = AircraftEventFolder:FindFirstChild("Enter")

}

Events.Enter.OnClientEvent:Connect(function(AircraftCamera)
	
	local AircraftTweenGoal = {}
	
	Cam.CameraType = "Attach"
	
	AircraftTweenGoal.CFrame = AircraftCamera.CFrame
	
	local TI = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
	
	local AircraftTween = TS:Create(Cam,TI,AircraftTweenGoal)
	
	AircraftTween:Play()
	
	wait(TI.Time)	
		
	Cam.CameraSubject = AircraftCamera
	
	
	
end)

Here is a video of it “flying”.

CFrame.fromEulerAnglesXYZ is usually used as a Rotation function so lets take a propeller as an example.

A plane has a spinning propeller and in coding terms we use fromEulerAnglesXYZ to spin the propeller.

Its basically just a way to rotate a part.

1 Like

Thanks. Could you please explain the Parameters? I went to https://developer.roblox.com/en-us/api-reference/datatype/CFrame but the explanation for the parameters wasn’t clear enough for me. Thanks again.

CFrame.fromEulerAnglesXYZ applies the rotation in Z,Y,X order (confusing I know) but in object space. The reason this is useful with aircraft is that an aircrafts pitch rotation is relative to their yaw and roll. If you roll 45 degrees to the left and pitch up, you don’t want to go straight up, you want to pitch up in the up direction relative to your object.

I guess the simplest way to describe it is applies a rotation in object space instead of world space. Which comes in handy when you’re planes use all 3 axises of rotation. In your video it seems they only use one so it might not be something that you will need.

1 Like

Thanks! I’ll continue to look into the Parameters.