Plane / Flight system?

Hi! I’m looking to create a Plane / Flight system like the video depicted below.
Currently I’ve created the initial system in which relies on Point & Click to adjust the CFrame of a AlignOrientation and using a AlignPosition to dictate the direction of movement etc.

I’m looking to create the slight tilt / turn effect as seen below as well as having the Camera behave in a similar fashion. Does anyone have any suggestions?

Code
self.AlignOrientation.CFrame = self.Base.CFrame
				self.AlignPosition.Position = self.Base.Position
				
				self.AlignOrientation.MaxAngularVelocity = math.huge
				self.AlignOrientation.MaxTorque = math.huge
				self.AlignPosition.MaxForce = math.huge
				
				Heartbeat = Server:GetService('RunService').Heartbeat:Connect(function(dt, ...)
					self.AlignPosition.Position = self.Base.Position + self.Base.CFrame.LookVector * Speed
					if Server:GetService('UserInputService'):IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
						self.AlignOrientation.CFrame = CFrame.lookAt(self.Base.Position, Core:GetMousePos(...))
							* CFrame.fromEulerAnglesXYZ(0, 0, math.rad(Rot))
					end
					if Server:GetService('UserInputService'):IsKeyDown(Enum.KeyCode.A) then
						Rot += Speed / 10
					elseif Server:GetService('UserInputService'):IsKeyDown(Enum.KeyCode.D) then
						Rot -= Speed / 10
					end
				end)

Bump?

Please help required, struggling with this.

you’d have to make a camera system that relies on lerps and stuff to get that smooth type of effect. are you familiar with coding cameras / custom camera systems?

1 Like

Not overly familiar but do have experience.
Outside of the camera Lerping though how would I go about create unrestricted 360° movement?

Unrestricted 360 degree movement can be a bit difficult due to gimbal lock. One solution is to use a quaternion. Depending on your existing math knowledge, this might be a bit confusing. Here’s an excellent video by 3Blue1Brown explaining them. You may also want to see Ben Eater’s video series on the topic (also linked under the 3Blue1Brown video).

That should cover the mathematical premise, but you’ll of course also want to actually use it in Luau. Here’s an implementation in Quenty’s Nevermore Engine. Unfortunately, it does not appear to be documented. EgoMoose also has an implementation and explanation here.

1 Like

Server:GetService(‘RunService’).RenderStepped:Connect(function(dt, …)

	self.Camera.CameraType = Enum.CameraType.Scriptable
	self.Camera.CFrame = Part.CFrame - Part.CFrame.LookVector * 5
	
	local mouse = UserInputService:GetMouseLocation()
	
	local center = Vector2.new(workspace.CurrentCamera.ViewportSize.X / 2, workspace.CurrentCamera.ViewportSize.Y / 2)
	local x, y, z = Part.CFrame:ToOrientation();
	AlignOrientation.CFrame = CFrame.new(AlignOrientation.CFrame.Position) * CFrame.fromOrientation(x + (-mouse.Y + center.Y) / (workspace.CurrentCamera.ViewportSize.Y / 1.25), y + (-mouse.X + center.X) / (workspace.CurrentCamera.ViewportSize.X / 1.25), z + (-mouse.X + center.X) / (workspace.CurrentCamera.ViewportSize.X / 1.25))
end)

So say this is the code I’m working off - It’s locked by Gimbal lock; how could I exceed that?

Springs are used to create the reactive camera you want. Springs transform the camera’s position in a way where it reacts to forces. Lots of front page games will implement this to simulate recoil with guns, simulate the camera being affected by external vehicle forces, and making UI move smoothly to create a better UX. TweenService:SmoothDamp() is an implementation of springs which have a set dampening value and give you less control. This doesn’t make them completely useless as they can still work in some cases. Libraries such as Ripple (which is the one I’m most familar with) will give you more control of springs. Other implementations of springs also exist and you are free to look for them. If you plan on using springs I recommend watching 5 Powerful Code Patterns Behind Roblox Games (Springs Section) and sleitnick’s Plane Camera FX video which will show you how the pattern can be implemented in your use case.

1 Like

I was able to replicate this by using Angular velocity rather than AlignOrientation.

I divided the screen into 4 segments to replicate Throttle and Steer using Camera.ViewportSize/2
then got the Players MouseLocation through UserInputService.

From that I worked out if the Mouse.X & Mouse.Y was > or < than the center points of the ViewportSize and adjusted accordingly.

From this I then worked out the distance of the Mouse from said center point: (Mouse.X - Center.X) and used math.abs to convert to a + number.

Finally using all the info gathered I adjusted the Pitch & Yaw based off the information and then * by the distance to act as the turn speed.

I use the VehicleSeats steer to dictate the Roll.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.