Hi there,
I’m trying to create a plane system, on the ground for now. I would like my plane to go forward at a speed depending on the throttle, and when I turn my mouse, the plane should turn. I’m unsure how to do this however.
Code:
local throttle = 0
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local userInputService = game:GetService("UserInputService")
local head = script.Parent.MainFrame.Background.ThrottleHead
local throttleIncrease = false
local throttleDecrease = false
local plane = workspace.Cessna
local main = plane.PlaneKit.Plane.MainParts.Main
local gyro = main.BodyGyro
local velocity = main.BodyVelocity
gyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
userInputService.InputBegan:Connect(function(input,game_processed)
if game_processed then return end
if input.KeyCode == Enum.KeyCode.W then
throttleIncrease = true
end
if input.KeyCode == Enum.KeyCode.S then
throttleDecrease = true
end
end)
userInputService.InputEnded:Connect(function(input,game_processed)
if game_processed then return end
if input.KeyCode == Enum.KeyCode.W then
throttleIncrease = false
end
if input.KeyCode == Enum.KeyCode.S then
throttleDecrease = false
end
end)
while wait() do
if throttleIncrease then
if throttle < 100 then
throttle = throttle + 1
end
end
if throttleDecrease then
if throttle >= 1 then
throttle = throttle - 1
end
end
head.Position = UDim2.new(-1.205, 0,throttle / 100, 0)
print(throttle)
local Direction = (mouse.Hit.Position - character.Head.Position).unit
velocity.Velocity = Vector3.new()
--gyro.CFrame = CFrame.fromOrientation(Direction.X, Direction.Y, Direction.Z)
end