I am working on a jets flight mechanics. So far, the jet flies in the proper direction (it flies in the mouse direction), however, the jet is not facing the mouse direction I am using BodyVelocity to move the jet and BodyGyro to rotate it to face the mouse direction, however, it’s not facing it properly (it does tilt though). What is the problem?

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local humanoid = character:WaitForChild("Humanoid")
local mouse = player:GetMouse()

local jet
local jetSeat
local leaveJet
local remotes

local CAS = game:GetService("ContextActionService")
local runService = game:GetService("RunService")

function onSit(seated, seat)
	if seated then
		remotes = seat.Parent:FindFirstChild("Remotes")
		jetSeat = seat
		jet = seat:FindFirstAncestor("Warzone Jet")
		
		if remotes then
			leaveJet = remotes.LeaveJet
			CAS:BindAction("Leave", leave, false, Enum.KeyCode.E, Enum.KeyCode.Space)
			runService:BindToRenderStep("Fly", 1, fly)
		end
	else
		jetSeat = nil
		jet = nil
		CAS:UnbindAction("Leave")
		runService:UnbindFromRenderStep("Fly")
	end
end

function leave(action, inputState)
	if inputState == Enum.UserInputState.Begin then
		if action == "Leave" then
			leaveJet:FireServer()
		end
	end
end

function fly()
	jet.PrimaryPart.BodyVelocity.Velocity = mouse.Hit.LookVector * 125
	jet.PrimaryPart.BodyGyro.CFrame = CFrame.new(jet.PrimaryPart.Position, mouse.Hit.Position)
end

humanoid.Seated:Connect(onSit)

2 comments

0

mouse.Hit.LookVector should also be used for CFrame

0

I tried that and it didn't work either, the jet doesn't face the mouse direction, it just stays fixed to a specific orientation while flying.