Camera manipulation

Hi devs!

I’m working on a flight system, I plan for the controls to be the "A and “D” keys (left and right) to control the Roll, and the camera to control the pitch and yaw (the direction).

Screenshot 2023-01-14 180537

How could I manipulate the camera so the plane goes to where the players camera is looking? (I plan for the camera to be locked behind the plane, like so ↓)

Any help is appreciated!

Anyone know how I can do this?

You can use the LookVector property of the player’s camera. Here’s an example of how to do that:

local RunService = game:GetService("RunService")
local Plane = workspace.Plane
local Camera = workspace.CurrentCamera

local speed = 5 -- studs/second
RunService.RenderStepped:Connect(function(deltaTime) -- run every frame before the frame
	-- uses deltaTime to make speed consistent
	Plane:PivotTo(Plane:GetPivot() * CFrame.new(Camera.CFrame.LookVector * speed * deltaTime))
end)

Note that this code will only move the plane on the client (as you need the client to get the camera), so you will need to use your own replication to the server.

1 Like

I don’t want the plane to move in the direction of the camera, I want the plane to face the direction of the camera, I’m going to use VectorForces for the movement.