So I’m trying to make a flying script. I’m using MoveDirection to figure out where the humanoid is moving. The problem is, even if I’m trying to move backwards, this moves me forwards. Shouldn’t it automatically detect that I’m trying to go backwards because I’m reading MoveDirection? I’m using a BodyVelocity to move:
If the flying script is for your own character, you can use UserInputService and detect which WASD keys are being pressed… Based off the user input, you can set a BodyVelocity instance value to a certain value so that the player moves in the intended direction.
Note:
Pressing both the W and S key will make the player move backwards because the S key overrides the W key for player movement - same thing for the A and D keys.
Yes, I’m using BodyVelocity. The code I posted works, it just always moves me forward. So like, even if I press “S”, it moves me forward. That’s my problem.
local p = game.Players.LocalPlayer
local c = p.Character
local hum = c.Humanoid
local hroot = c.HumanoidRootPart
local bv = Instance.new("BodyVelocity")
bv.Parent = hroot
bv.MaxForce = Vector3.new(99999, 99999, 99999)
bv.Velocity = Vector3.new(0, 0, 0)
while true do
wait()
local Velocity = hum.MoveDirection + game.Workspace.CurrentCamera.CoordinateFrame.lookVector * Vector3.new(10, 10, 10)
bv.Velocity = Velocity
end
Option 2
local p = game.Players.LocalPlayer
local c = p.Character
local hum = c.Humanoid
local hroot = c.HumanoidRootPart
local bv = Instance.new("BodyVelocity")
bv.Parent = hroot
bv.MaxForce = Vector3.new(99999, 99999, 99999)
bv.Velocity = Vector3.new(0, 0, 0)
while true do
wait()
local Velocity = hum.MoveDirection* Vector3.new(10, 0, 10) + game.Workspace.CurrentCamera.CoordinateFrame.lookVector * Vector3.new(0, 10, 0)
bv.Velocity = Velocity
end
If you want the character’s moving direction to really affect the velocity, use option 2…
You can open a blank studio, and paste an “option” into a local script… and try the other one after.