How to make plane steer with mouse instead of camera?

Hello Developers!

I am currently trying to edit a simple plane script.

  1. What do you want to achieve?
    Currently, the plane follows the player’s camera. I would like the plane to instead follow the player’s mouse.
  2. What have you tried so far?
    I’ve tried getting the position of the mouse in order to steer the plane, but it either doesn’t steer or the plane still follows the camera.

I’ve looked all over the internet for a fix, but cant seem to find one that works.

Here is the current script.

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local Player = Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()
local PilotSeat = script:WaitForChild("PilotSeat").Value
local BodyGyro = PilotSeat:WaitForChild("BodyGyro")
local BodyVelocity = PilotSeat:WaitForChild("BodyVelocity")
local position = Vector2.new(Mouse.X, Mouse.Y)
local function getPlaneMass()
	local PlaneMass = 0
	for _, v in pairs(PilotSeat.Parent:GetDescendants()) do
		if v:IsA("BasePart") then
			PlaneMass = PlaneMass + v:GetMass()
		end
	end
	return PlaneMass
end
Camera.CameraType = Enum.CameraType.Custom
Camera.CFrame = PilotSeat.CFrame
Camera.CameraSubject = PilotSeat
local Throttle = 0
local ThrottleIncrease = false
local ThrottleDecrease = false
local SteerActive = false
local inAir = false
local Vector3GravityBypass = Vector3.new(getPlaneMass() * workspace.Gravity, getPlaneMass() * workspace.Gravity, getPlaneMass() * workspace.Gravity)
BodyVelocity.MaxForce = Vector3GravityBypass
BodyGyro.MaxTorque = Vector3GravityBypass
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.W then
				ThrottleIncrease = true
			end
			if input.KeyCode == Enum.KeyCode.S then
				ThrottleDecrease = true
			end
			if input.KeyCode == Enum.KeyCode.E then
				SteerActive = true
			end
		end
	end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.W then
				ThrottleIncrease = false
			end
			if input.KeyCode == Enum.KeyCode.S then
				ThrottleDecrease = false
			end
			if input.KeyCode == Enum.KeyCode.E then
				SteerActive = false
			end
		end
	end
end)
while wait() do
	local SteerCFrame = Camera.CFrame
	if ThrottleIncrease then
		Throttle = math.clamp(Throttle + 1, 0, PilotSeat.MaxSpeed)
	end
	if ThrottleDecrease then
		Throttle = math.clamp(Throttle - 1, 0, PilotSeat.MaxSpeed)
	end
	if SteerActive then
		SteerCFrame = workspace.CurrentCamera.CFrame
	end
	if PilotSeat.Velocity.magnitude >= 50 then
		inAir = true
	else
		inAir = false
	end
	if inAir then
		BodyGyro.CFrame = CFrame.new(SteerCFrame.Position, SteerCFrame.Position + SteerCFrame.LookVector * 20)
	else
		BodyGyro.CFrame = CFrame.new(SteerCFrame.Position, SteerCFrame.Position + Vector3.new(SteerCFrame.LookVector.X, 0, SteerCFrame.LookVector.Z) * 20)
	end
	if Throttle >= 25 then
		BodyVelocity.MaxForce = Vector3GravityBypass * Throttle
	else
		BodyVelocity.MaxForce = (Vector3GravityBypass * Throttle) / 2
	end
	BodyVelocity.Velocity = SteerCFrame.LookVector * Throttle
	if not PilotSeat or PilotSeat:WaitForChild("CoreScript"):WaitForChild("Player").Value == nil then
		break
	end
end
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character.Humanoid
script:Destroy()

(I did not make this script, I am simply trying to edit it to my liking)

If someone could please point in the right direction, that would be greatly appreciated.
(If someone already made a dev forum post about something similar, could you please link it?)

Thanks in advance!

2 Likes

set the body gyro cframe to the mouse.Hit

BodyGyro.CFrame = mouse.Hit

Edit- Don’t know if you saw already but just do above^ forget about the speed variable. My mistake

I changed it, but the plane doesn’t want to turn anymore or even go forward. (There are no errors in the output.)

BodyGyro.CFrame = CFrame.new(planebody.Position,Mouse.Hit.P))

And if you want the plane to angle it’s self as it turns for a more realistic effect you can add this to the end

  • CFrame.Angles(0,-3.14/2+1.6,planebody.RotVelocity.Y/3)

The “planebody” is the main part of the plane or main fuselage. The main piece.

I can’t figure this out… If you would like, Heres the plane kit Im using: PilotSeat - Roblox

I’ll fix it for you right now.

Here you go. I’ve edited a couple of things inside but it should work properly for you now. Just make sure to go inside the client script and redefine “Main Part” in the script and plane model if you decide to use a different model for the plane. I’ve also disabled the old steering system/camera system the original creator added in and implemented the features you wanted.

https://www.roblox.com/library/6556022857/PilotSeatPackage-Created-by-DAW588-edited-devf

1 Like

now with mobile support

thanks :smiley:
2 years later??
(fixed now)

1 Like