Advertisement
Guest User

Movement

a guest
Feb 11th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.62 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local Client = game.Players.LocalPlayer
  3. repeat wait() until Client.Character
  4. local Character = Client.Character
  5. local WeldBrick = Instance.new("Part")
  6. WeldBrick.Size = Vector3.new(2,6,2)
  7. WeldBrick.CanCollide = false
  8. WeldBrick.Anchored = false
  9. WeldBrick.Transparency = 1
  10. WeldBrick.Massless = true
  11. WeldBrick.Name = "WeldBrick"
  12.  
  13. local Weld = Instance.new("Weld")
  14. Weld.Parent = Character.HumanoidRootPart
  15. Weld.Part0 = Character.HumanoidRootPart
  16. WeldBrick.Parent = Character
  17. Weld.Part1 = WeldBrick
  18. Weld.C0 = CFrame.new(0,0,0)
  19. local Forward = Instance.new("BodyThrust")
  20. --Forward.P = 1000
  21. --Forward.MaxForce = Vector3.new(0,0,0)
  22. Forward.Force = Vector3.new(0,0,0)
  23. Forward.Parent = Character.HumanoidRootPart
  24. local Back = Instance.new("BodyThrust")
  25. --Back.P = 1000
  26. --Back.MaxForce = Vector3.new(0,0,0)
  27. Back.Force = Vector3.new(0,0,0)
  28. Back.Parent = Character.HumanoidRootPart
  29. local Left = Instance.new("BodyThrust")
  30. --Left.P = 1000
  31. --Left.MaxForce = Vector3.new(0,0,0)
  32. Left.Force = Vector3.new(0,0,0)
  33. Left.Parent = Character.HumanoidRootPart
  34. local Right = Instance.new("BodyThrust")
  35. --Right.P = 1000
  36. --Right.MaxForce = Vector3.new(0,0,0)
  37. Right.Force = Vector3.new(0,0,0)
  38. Right.Parent = Character.HumanoidRootPart
  39. local DefaultMovementSpeed = script:WaitForChild("test")
  40.  
  41. local CurrentSpeedVector = Vector3.new()
  42.  
  43. local W = false
  44. local S = false
  45. local A = false
  46. local D = false
  47. local AppliedW = false
  48. local AppliedS = false
  49. local AppliedA = false
  50. local AppliedD = false
  51. local divider = 1.5
  52.  
  53. Character.Humanoid.WalkSpeed = 5
  54.  
  55. local function Move(Specifier)
  56.     print(Specifier)
  57.     if Specifier == "forward" then
  58.         Forward.Force = Vector3.new(0,0,-DefaultMovementSpeed.Value)
  59.         Back.Force = Vector3.new(0,0,0)
  60.         Left.Force = Vector3.new(0,0,0)
  61.         Right.Force = Vector3.new(0,0,0)
  62.     elseif Specifier == "forward right" then
  63.         Forward.Force = Vector3.new(0,0,-(DefaultMovementSpeed.Value/divider))
  64.         Back.Force = Vector3.new(0,0,0)
  65.         Left.Force = Vector3.new(0,0,0)
  66.         Right.Force = Vector3.new((DefaultMovementSpeed.Value/divider),0,0)
  67.     elseif Specifier == "forward left" then
  68.         Forward.Force = Vector3.new(0,0,-(DefaultMovementSpeed.Value/divider))
  69.         Back.Force = Vector3.new(0,0,0)
  70.         Left.Force = Vector3.new((-DefaultMovementSpeed.Value/divider), 0,0)
  71.         Right.Force = Vector3.new(0,0,0)
  72.     elseif Specifier == "left" then
  73.         Forward.Force = Vector3.new(0,0,0)
  74.         Back.Force = Vector3.new(0,0,0)
  75.         Left.Force = Vector3.new(-DefaultMovementSpeed.Value,0,0)
  76.         Right.Force = Vector3.new(0,0,0)
  77.     elseif Specifier == "right" then
  78.         Forward.Force = Vector3.new(0,0,0)
  79.         Back.Force = Vector3.new(0,0,0)
  80.         Left.Force = Vector3.new(0,0,0)
  81.         Right.Force = Vector3.new(DefaultMovementSpeed.Value,0,0)
  82.     elseif Specifier == "backward" then
  83.         Forward.Force = Vector3.new(0,0,0)
  84.         Back.Force = Vector3.new(0,0,DefaultMovementSpeed.Value)
  85.         Left.Force = Vector3.new(0,0,0)
  86.         Right.Force = Vector3.new(0,0,0)
  87.     elseif Specifier == "backward right" then
  88.         Forward.Force = Vector3.new(0,0,0)
  89.         Back.Force = Vector3.new(0,0,(DefaultMovementSpeed.Value/divider))
  90.         Left.Force = Vector3.new(0,0,0)
  91.         Right.Force = Vector3.new((DefaultMovementSpeed.Value/divider),0,0)
  92.     elseif Specifier == "backward left" then
  93.         Forward.Force = Vector3.new(0,0,0)
  94.         Back.Force = Vector3.new(0,0,(DefaultMovementSpeed.Value/divider))
  95.         Left.Force = Vector3.new((-DefaultMovementSpeed.Value/divider), 0,0)
  96.         Right.Force = Vector3.new(0,0,0)
  97.     elseif Specifier == "stop" then
  98.         Forward.Force = Vector3.new(0,0,0)
  99.         Back.Force = Vector3.new(0,0,0)
  100.         Left.Force = Vector3.new(0,0,0)
  101.         Right.Force = Vector3.new(0,0,0)
  102.     end
  103.    
  104. end
  105.  
  106. local function DetermineMovement()
  107.     if W == true then -- forward
  108.         if D == false and A == false and S == false then
  109.             Move("forward")
  110.            
  111.         elseif D == true and A == false and S == false then
  112.             Move("forward right")
  113.            
  114.         elseif D == false and A == true and S == false then
  115.             Move("forward left")
  116.         elseif D == true and A == true and S == false then
  117.             Move("forward")
  118.         elseif D == true and A == true and S == true then
  119.             Move("stop")
  120.         elseif D == false and A == false and S == true then
  121.             Move("stop")
  122.         elseif D == true and A == false and S == true then
  123.             Move("right")
  124.         elseif D == false and A == true and S == true then
  125.             Move("left")
  126.         end
  127.             return
  128.         end -- forward
  129.     if S == true then
  130.         if D == false and A == false and W == false then
  131.             Move("backward")
  132.         elseif D == true and A == false and W == false then
  133.             Move("backward right")
  134.         elseif D == false and A == true and W == false then
  135.             Move("backward left")
  136.         elseif D == true and A == true and W == false then
  137.             Move("backward")
  138.         elseif D == true and A == true and W == true then
  139.             Move("stop")
  140.         elseif D == false and A == false and W == true then
  141.             Move("stop")
  142.         elseif D == true and A == false and W == true then
  143.             Move("right")
  144.         elseif D == false and A == true and W == true then
  145.             Move("left")
  146.         end
  147.         return
  148.     end
  149.     if D == true then
  150.         if W == false and S == false and A == false then
  151.             Move("right")
  152.         elseif W == true and S == false and A == false then
  153.             Move("forward right")
  154.         elseif W == false and S == true and A == false then
  155.             Move("backward right")
  156.         elseif W == true and S == true and A == false then
  157.             Move("right")
  158.         elseif W == true and S == true and A == true then
  159.             Move("stop")
  160.         elseif W == false and S == false and A == true then
  161.             Move("stop")
  162.         elseif W == true and S == false and A == true then
  163.             Move("forward")
  164.         elseif W == false and S == true and A == true then
  165.             Move("backward")
  166.         end
  167.         return
  168.     end
  169.     if A == true then
  170.         if W == false and S == false and D == false then
  171.             Move("left")
  172.         elseif W == true and S == false and D == false then
  173.             Move("forward left")
  174.         elseif W == false and S == true and D == false then
  175.             Move("backward left")
  176.         elseif W == true and S == true and D == false then
  177.             Move("left")
  178.         elseif W == true and S == true and D == true then
  179.             Move("stop")
  180.         elseif W == false and S == false and D == true then
  181.             Move("stop")
  182.         elseif W == true and S == false and D == true then
  183.             Move("forward")
  184.         elseif W == false and S == true and D == true then
  185.             Move("backward")
  186.         end
  187.         return
  188.     end
  189.     if W == false and S == false and A == false and D == false then
  190.         Move("stop")
  191.         return
  192.     end
  193. end
  194.    
  195. local function HandleMovementInput(input, gameprocessed)
  196.     if input.KeyCode == Enum.KeyCode.W then
  197.         W=true
  198.         DetermineMovement()
  199.     elseif input.KeyCode == Enum.KeyCode.S then
  200.         S=true
  201.         DetermineMovement()
  202.     elseif input.KeyCode == Enum.KeyCode.A then
  203.         A=true
  204.         DetermineMovement()
  205.     elseif input.KeyCode == Enum.KeyCode.D then
  206.         D=true
  207.         DetermineMovement()
  208.     end
  209. end
  210.  
  211. local function HandleMovementOutput(input, gameprocessed)
  212.     if input.KeyCode == Enum.KeyCode.W then
  213.         W=false
  214.         DetermineMovement()
  215.     elseif input.KeyCode == Enum.KeyCode.S then
  216.         S=false
  217.         DetermineMovement()
  218.     elseif input.KeyCode == Enum.KeyCode.A then
  219.         A=false
  220.         DetermineMovement()
  221.     elseif input.KeyCode == Enum.KeyCode.D then
  222.         D=false
  223.         DetermineMovement()
  224.     end
  225. end
  226.  
  227. local function HandleTouch(TouchPart)
  228.     if TouchPart.Name == "JumpPart" then
  229.         Character.HumanoidRootPart.Velocity = Character.HumanoidRootPart.Velocity + Vector3.new(0,100,0)
  230.     end
  231. end
  232. for _, v in pairs(Character:GetChildren()) do
  233.     if v:IsA("Part") or v:IsA("UnionOperation") then if v.Name ~= "HumanoidRootPart" then v.Massless = true end end
  234. end
  235. Character["RightFoot"].Touched:Connect(HandleTouch)
  236. Character["LeftFoot"].Touched:Connect(HandleTouch)
  237.  
  238. UserInputService.InputBegan:Connect(HandleMovementInput)
  239. UserInputService.InputEnded:Connect(HandleMovementOutput)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement