Flying Humanoid state and flying in multiple directions

Trying to create a fly script through modifying something else I found on the forums, however, I am failing at 2 things:

  1. The humanoid is in the falling state, and after expirementing with all the states you can use set state on, it seems there is no state that would cause the humanoid to not play an animation yet still face the direction the camera faces

  2. Through using body velocities the humanoid is able to move in the air, however, it is incapable of moving in 2 directions at once (such as front and right), as it seems like it would only Instance.new a single body velocity even when both buttons are pressed.

(I dont think theres a rule against asking 2 related questions in a post, if there is, oopsies)

here is the script:

local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local camera = game.Workspace.CurrentCamera
local LastTapped, Tapped = false, false
local flyUpSpeed = 20
local flyDownSpeed = 20
local wdown = false
local flying = false
local speed = 0.5
local bp = nil
local bodyVel = nil
local bv2 = nil
local bv3 = nil
local bv4 = nil



bp = Instance.new("BodyPosition",hrp)
bp.MaxForce = Vector3.new()
bp.D = 100
flying = true
bp.Position = hrp.Position + Vector3.new(0,10,0)
bp.MaxForce = Vector3.new(400000,400000,400000)


uis.InputBegan:connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.W then
		hum:ChangeState(Enum.HumanoidStateType.FallingDown)
		if bp then
			bp:Destroy()
			bp = nil
		end
		bodyVel = Instance.new("BodyVelocity",hrp)
		bodyVel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		while flying and wait() do
			bodyVel.Velocity = camera.CFrame.LookVector*speed*100
		end
	elseif Input.KeyCode == Enum.KeyCode.A then
		hum:ChangeState(Enum.HumanoidStateType.FallingDown)
		if bp then
			bp:Destroy()
			bp = nil
		end
		bv2 = Instance.new("BodyVelocity", hrp)
		print(bv2)
		bv2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		while flying and wait() do
			bv2.Velocity = camera.CFrame.RightVector*speed*-100
		end
	elseif Input.KeyCode == Enum.KeyCode.D then
		hum:ChangeState(Enum.HumanoidStateType.FallingDown)
		if bp then
			bp:Destroy()
			bp = nil
		end
		bv3 = Instance.new("BodyVelocity", hrp)
		print(bv2)
		bv3.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		while flying and wait() do
			bv3.Velocity = camera.CFrame.RightVector*speed*100
		end
	elseif Input.KeyCode == Enum.KeyCode.S then
		hum:ChangeState(Enum.HumanoidStateType.FallingDown)
		if bp then
			bp:Destroy()
			bp = nil
		end
		bv4 = Instance.new("BodyVelocity", hrp)
		bv4.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		while flying and wait() do
			bv4.Velocity = camera.CFrame.LookVector*speed*-100
		end
	end
end)

uis.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.W then
		bodyVel:Destroy()
		print(bp)
		if not bp then
			bp = Instance.new("BodyPosition",hrp)
			bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			bp.D = 100
			bp.Position = hrp.Position
		end
	elseif Input.KeyCode == Enum.KeyCode.A then
		bv2:Destroy()
		if not bp then
			bp = Instance.new("BodyPosition",hrp)
			bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			bp.D = 100
			bp.Position = hrp.Position
		end
	elseif Input.KeyCode == Enum.KeyCode.D then
		bv3:Destroy()
		if not bp then
			bp = Instance.new("BodyPosition",hrp)
			bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			bp.D = 100
			bp.Position = hrp.Position
		end
	elseif Input.KeyCode == Enum.KeyCode.S then
		bv4:Destroy()
		if not bp then
			bp = Instance.new("BodyPosition",hrp)
			bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			bp.D = 100
			bp.Position = hrp.Position
		end
	end
end)

and yea the script probably sucks lol

bru 1 love no reply
ples reply
sagde

Think I figured out the problem: multiple bodyvelocities would result in only one of them actually applying the force

alr, managed to get it to work. I simply had to use 4 vector3 variables, each for a input key, then add them together to achieve movement. To achieve not floating off, I simply had to use another 4 vairables to stop the 4 loops setting the 4 previously mentioned vector3s, then set the vector3 to 0, 0, 0 and add in a bodyposition if the player isn’t moving at all!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.