Hello Developers!
I am currently trying to edit a simple plane script.
-
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. -
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!