Alright, I actually got some basics working- I can’t figure out how to make the script work when I put the VectorForce and BodyGyro in a different part outside of the VehicleSeat, or if I group it- for whatever reason it causes an infinite yield or something so I’d rather avoid it, but I might just end up putting the part inside of the seat hierarchy wise rather than beside it in the same group-- but for now both are in the seat itself, I’m just happy that it works.
I will definitely need a script that makes the camera stick to the avatar itself rather than being bound to the world, it would make controlling the ship a whole lot easier.
Script for controlling the Gyro:
-- Services
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
-- Variables
local seat = workspace:WaitForChild("VehicleSeat")
local gyro = seat:FindFirstChildOfClass("BodyGyro")
-- Function to check if the player is sitting in the seat
local function isPlayerSittingInSeat(player)
if seat.Occupant then
local character = player.Character
if character and seat.Occupant == character:FindFirstChildOfClass("Humanoid") then
return true
end
end
return false
end
-- These here functions handle ship rotation (using the arrow keys, I'll add console controller inputs in the future)
-- Z AXIS (rotating left and right )
local function onKeyPressRight(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.KeypadSix then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
gyro.CFrame = gyro.CFrame * CFrame.Angles(0, 0, math.rad(-15)) -- Rotate the ship -15 degrees on the Z axis
end
end
end
local function onKeyPressLeft(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.KeypadFour then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
gyro.CFrame = gyro.CFrame * CFrame.Angles(0, 0, math.rad(15)) -- Rotate the ship -15 degrees on the Z axis
end
end
end
-- Y AXIS (turning left and right)
local function onKeyPressTurnR(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.KeypadNine then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
gyro.CFrame = gyro.CFrame * CFrame.Angles(0, math.rad(-15), 0) -- Rotate the ship -15 degrees on the Y axis
end
end
end
local function onKeyPressTurnL(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.KeypadSeven then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
gyro.CFrame = gyro.CFrame * CFrame.Angles(0, math.rad(15), 0) -- Rotate the ship 15 degrees on the Y axis
end
end
end
-- X AXIS (Rotating forward and backward)
local function onKeyPressBack(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.KeypadTwo then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
gyro.CFrame = gyro.CFrame * CFrame.Angles(math.rad(15), 0, 0) -- Rotate the ship 15 degrees on the X axis
end
end
end
local function onKeyPressForward(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.KeypadEight then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
gyro.CFrame = gyro.CFrame * CFrame.Angles(math.rad(-15), 0, 0) -- Rotate the ship -15 degrees on the X axis
end
end
end
-- Connect the input events
UserInputService.InputBegan:Connect(onKeyPressRight)
UserInputService.InputBegan:Connect(onKeyPressLeft)
UserInputService.InputBegan:Connect(onKeyPressTurnL)
UserInputService.InputBegan:Connect(onKeyPressTurnR)
UserInputService.InputBegan:Connect(onKeyPressBack)
UserInputService.InputBegan:Connect(onKeyPressForward)
And the script for controlling the elevation-
-- Services
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
-- Variables
local seat = workspace:WaitForChild("VehicleSeat")
local vectorForce = seat:FindFirstChildOfClass("VectorForce")
-- Function to check if the player is sitting in the seat
local function isPlayerSittingInSeat(player)
if seat.Occupant then
local character = player.Character
if character and seat.Occupant == character:FindFirstChildOfClass("Humanoid") then
return true
end
end
return false
end
-- Q
local function onKeyPressQ(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.Q then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
vectorForce.Force = Vector3.new(0, -5000, 0)
end
end
end
local function onKeyReleaseQ(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.Q then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
vectorForce.Force = Vector3.new(0, 0, 0)
end
end
end
--E
local function onKeyPressE(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.E then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
vectorForce.Force = Vector3.new(0, 5000, 0)
end
end
end
local function onKeyReleaseE(input, gameProcessed)
-- Only proceed if the input is not processed by the game and is the desired key
if not gameProcessed and input.KeyCode == Enum.KeyCode.E then
local player = Players.LocalPlayer
if isPlayerSittingInSeat(player) then
vectorForce.Force = Vector3.new(0, 0, 0)
end
end
end
-- Connect the input events
UserInputService.InputBegan:Connect(onKeyPressQ)
UserInputService.InputEnded:Connect(onKeyReleaseQ)
UserInputService.InputBegan:Connect(onKeyPressE)
UserInputService.InputEnded:Connect(onKeyReleaseE)
If anything I can improve upon them further!