So here I have a flying system thing and its follow’s the player’s mouse. But I don’t want the character looking towards the camera
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local myPlayer = game.Players.LocalPlayer
local myChar = myPlayer.Character or myPlayer.CharacterAdded:Wait()
local myHRP = myChar:WaitForChild("HumanoidRootPart")
local mouse = myPlayer:GetMouse()
local camera = workspace.CurrentCamera
local flying = false
local speed = 0.5
game.ReplicatedStorage.FlameEvent.OnClientEvent:Connect(function()
local bp = Instance.new("BodyPosition", myHRP)
bp.MaxForce = Vector3.new()
bp.D = 10
bp.P = 10000
local bg = Instance.new("BodyGyro", myHRP)
bg.MaxTorque = Vector3.new()
bg.D = 10
local function fly()
flying = true
bp.MaxForce = Vector3.new(400000, 400000, 400000)
bg.MaxTorque = Vector3.new(400000, 400000, 400000)
task.spawn(function()
while flying do
rs.RenderStepped:Wait()
bp.Position = myHRP.Position + ((myHRP.Position - mouse.Hit.p).unit * speed)
bg.CFrame = CFrame.new(mouse.Hit.p, myHRP.Position)
end
end)
end
local function endFlying()
bp.MaxForce = Vector3.new()
bg.MaxTorque = Vector3.new()
flying = false
end
uis.InputBegan:Connect(function(input,processed)
if input.KeyCode == Enum.KeyCode.E then
fly()
end
end)
uis.InputEnded:Connect(function(input,processed)
if input.KeyCode == Enum.KeyCode.E then
endFlying()
end
end)
end)
I tried to use as much of your script as possible. Think I only removed a camera reference.
This is linked to button W. As in, that must be down to be able to toggle E to start flying.
When you let off W everything resets. Also need to look up to get off the ground.
The flight follows the mouse. If aimed right, it will float right-ish.
The player follows the player direction. If turned right, it will turn right.
Turn holding down right mouse as normally while moving.
All in all I think this is workable compromise …
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local myPlayer = game.Players.LocalPlayer
local myChar = myPlayer.Character or myPlayer.CharacterAdded:Wait()
local myHRP = myChar:WaitForChild("HumanoidRootPart")
local myHP = myChar:WaitForChild("Humanoid")
local mouse = myPlayer:GetMouse()
local flying = false
local speed = 0.5
game.ReplicatedStorage.FlameEvent.OnClientEvent:Connect(function()
local newCFrame = CFrame.Angles(0, math.rad(180), 0)
local bp = Instance.new("BodyPosition", myHRP)
bp.MaxForce = Vector3.new()
bp.D = 10
bp.P = 10000
local bg = Instance.new("BodyGyro", myHRP)
bg.MaxTorque = Vector3.new()
bg.D = 10
local function fly()
flying = true
bp.MaxForce = Vector3.new(400000, 400000, 400000)
bg.MaxTorque = Vector3.new(400000, 400000, 400000)
task.spawn(function()
while flying do rs.RenderStepped:Wait()
myHP.Jump = true
bp.Position = myHRP.Position -((myHRP.Position - mouse.Hit.p).unit * speed)
bg.CFrame = CFrame.new(mouse.Hit.p, myHRP.Position)
local newCFrame = CFrame.Angles(0, math.rad(myHRP.Orientation.Y), 0)
bg.CFrame = newCFrame
end
end)
end
local function endFlying()
bp.MaxForce = Vector3.new()
bg.MaxTorque = Vector3.new()
flying = false
end
uis.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.E then
if uis:IsKeyDown(Enum.KeyCode.W) then
fly()
end
end
end)
uis.InputEnded:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.W then
endFlying()
end
end)
end)
For others that may want to try this you will need to create an event named FlameEvent in ReplicatedStorage then trigger it with a short script (workspace be fine) for testing.
task.wait(3)
local rs = game:GetService("ReplicatedStorage")
rs.FlameEvent:FireAllClients()