Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Fly script inverts my controls if I face backwards?

Asked by 2 years ago

I'm trying to make a fly script that uses CFrame.LookVector and CFrame.RightVector and if works fine if I only face forward, however if I turn around my controls are inverted (W makes you go backwards, S makes you go forward etc). I have a video that is not very clear but hopefully you will see what I mean. This is my code:

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")

hum.PlatformStand = true
hrp.Anchored = true

game:GetService("RunService").Stepped:Connect(function()
    hrp.CFrame = CFrame.new(hrp.CFrame.Position, hrp.CFrame.Position + workspace.CurrentCamera.CFrame.LookVector)
    if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.W) then
        hrp.CFrame = hrp.CFrame * CFrame.new(workspace.CurrentCamera.CFrame.LookVector)
    end
    if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.A) then
        hrp.CFrame = hrp.CFrame * CFrame.new(workspace.CurrentCamera.CFrame.RightVector):Inverse()
    end
    if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.S) then
        hrp.CFrame = hrp.CFrame * CFrame.new(workspace.CurrentCamera.CFrame.LookVector):Inverse()
    end
    if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.D) then
        hrp.CFrame = hrp.CFrame * CFrame.new(workspace.CurrentCamera.CFrame.RightVector)
    end
end)

I wasn't getting any errors in the console so I don't know how to fix it.

0
ah s-,this is confusing maybe i should messing around in studio with ur script lamgogo 56 — 2y
0
after testing the code and do somethings for it,i found out that use lookvector in ur case(something like while making character fly like ur) wont work much cuz the lookvector cannot update while u doin that so it will just fly to the last lookvec got updated lamgogo 56 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

I fixed it by using a BodyVelocity and leaving the hrp unanchored. Thanks for your responses!

Ad

Answer this question