wait(2) local player = game.Players.LocalPlayer local BV = Instance.new("BodyVelocity", player.Character.HumanoidRootPart) BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge) local UIP = game:GetService("UserInputService") local camera = workspace.CurrentCamera UIP.InputBegan:Connect(function(Key) if Key.KeyCode == Enum.KeyCode.W then BV.Velocity = camera.CFrame.LookVector*100 elseif Key.KeyCode == Enum.KeyCode.S then BV.Velocity = camera.CFrame.LookVector*-100 elseif Key.KeyCode == Enum.KeyCode.A then BV.Velocity = -(camera.CFrame.LookVector * camera.CFrame.Z) --faulty elseif Key.KeyCode == Enum.KeyCode.D then BV.Velocity = -(camera.CFrame.LookVector *- camera.CFrame.Z) -- faulty end end)
I am trying to make it so when you press A or D you go to the right or left always, taking camera CFrame into count. I got it on W and S but on A and D it just goes one direction no matter where I look. How do I fix this?
If you wanna try this out, put it in playergui and you will see what I mean.
use for right camera.CFrame.Rightvector*100
use for left camera.CFrame.Rightvector*-100
that should fix it