Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local UserInputService = game:GetService("UserInputService")
- local Client = game.Players.LocalPlayer
- repeat wait() until Client.Character
- local Character = Client.Character
- local WeldBrick = Instance.new("Part")
- WeldBrick.Size = Vector3.new(2,6,2)
- WeldBrick.CanCollide = false
- WeldBrick.Anchored = false
- WeldBrick.Transparency = 1
- WeldBrick.Massless = true
- WeldBrick.Name = "WeldBrick"
- local Weld = Instance.new("Weld")
- Weld.Parent = Character.HumanoidRootPart
- Weld.Part0 = Character.HumanoidRootPart
- WeldBrick.Parent = Character
- Weld.Part1 = WeldBrick
- Weld.C0 = CFrame.new(0,0,0)
- local Forward = Instance.new("BodyThrust")
- --Forward.P = 1000
- --Forward.MaxForce = Vector3.new(0,0,0)
- Forward.Force = Vector3.new(0,0,0)
- Forward.Parent = Character.HumanoidRootPart
- local Back = Instance.new("BodyThrust")
- --Back.P = 1000
- --Back.MaxForce = Vector3.new(0,0,0)
- Back.Force = Vector3.new(0,0,0)
- Back.Parent = Character.HumanoidRootPart
- local Left = Instance.new("BodyThrust")
- --Left.P = 1000
- --Left.MaxForce = Vector3.new(0,0,0)
- Left.Force = Vector3.new(0,0,0)
- Left.Parent = Character.HumanoidRootPart
- local Right = Instance.new("BodyThrust")
- --Right.P = 1000
- --Right.MaxForce = Vector3.new(0,0,0)
- Right.Force = Vector3.new(0,0,0)
- Right.Parent = Character.HumanoidRootPart
- local DefaultMovementSpeed = script:WaitForChild("test")
- local CurrentSpeedVector = Vector3.new()
- local W = false
- local S = false
- local A = false
- local D = false
- local AppliedW = false
- local AppliedS = false
- local AppliedA = false
- local AppliedD = false
- local divider = 1.5
- Character.Humanoid.WalkSpeed = 5
- local function Move(Specifier)
- print(Specifier)
- if Specifier == "forward" then
- Forward.Force = Vector3.new(0,0,-DefaultMovementSpeed.Value)
- Back.Force = Vector3.new(0,0,0)
- Left.Force = Vector3.new(0,0,0)
- Right.Force = Vector3.new(0,0,0)
- elseif Specifier == "forward right" then
- Forward.Force = Vector3.new(0,0,-(DefaultMovementSpeed.Value/divider))
- Back.Force = Vector3.new(0,0,0)
- Left.Force = Vector3.new(0,0,0)
- Right.Force = Vector3.new((DefaultMovementSpeed.Value/divider),0,0)
- elseif Specifier == "forward left" then
- Forward.Force = Vector3.new(0,0,-(DefaultMovementSpeed.Value/divider))
- Back.Force = Vector3.new(0,0,0)
- Left.Force = Vector3.new((-DefaultMovementSpeed.Value/divider), 0,0)
- Right.Force = Vector3.new(0,0,0)
- elseif Specifier == "left" then
- Forward.Force = Vector3.new(0,0,0)
- Back.Force = Vector3.new(0,0,0)
- Left.Force = Vector3.new(-DefaultMovementSpeed.Value,0,0)
- Right.Force = Vector3.new(0,0,0)
- elseif Specifier == "right" then
- Forward.Force = Vector3.new(0,0,0)
- Back.Force = Vector3.new(0,0,0)
- Left.Force = Vector3.new(0,0,0)
- Right.Force = Vector3.new(DefaultMovementSpeed.Value,0,0)
- elseif Specifier == "backward" then
- Forward.Force = Vector3.new(0,0,0)
- Back.Force = Vector3.new(0,0,DefaultMovementSpeed.Value)
- Left.Force = Vector3.new(0,0,0)
- Right.Force = Vector3.new(0,0,0)
- elseif Specifier == "backward right" then
- Forward.Force = Vector3.new(0,0,0)
- Back.Force = Vector3.new(0,0,(DefaultMovementSpeed.Value/divider))
- Left.Force = Vector3.new(0,0,0)
- Right.Force = Vector3.new((DefaultMovementSpeed.Value/divider),0,0)
- elseif Specifier == "backward left" then
- Forward.Force = Vector3.new(0,0,0)
- Back.Force = Vector3.new(0,0,(DefaultMovementSpeed.Value/divider))
- Left.Force = Vector3.new((-DefaultMovementSpeed.Value/divider), 0,0)
- Right.Force = Vector3.new(0,0,0)
- elseif Specifier == "stop" then
- Forward.Force = Vector3.new(0,0,0)
- Back.Force = Vector3.new(0,0,0)
- Left.Force = Vector3.new(0,0,0)
- Right.Force = Vector3.new(0,0,0)
- end
- end
- local function DetermineMovement()
- if W == true then -- forward
- if D == false and A == false and S == false then
- Move("forward")
- elseif D == true and A == false and S == false then
- Move("forward right")
- elseif D == false and A == true and S == false then
- Move("forward left")
- elseif D == true and A == true and S == false then
- Move("forward")
- elseif D == true and A == true and S == true then
- Move("stop")
- elseif D == false and A == false and S == true then
- Move("stop")
- elseif D == true and A == false and S == true then
- Move("right")
- elseif D == false and A == true and S == true then
- Move("left")
- end
- return
- end -- forward
- if S == true then
- if D == false and A == false and W == false then
- Move("backward")
- elseif D == true and A == false and W == false then
- Move("backward right")
- elseif D == false and A == true and W == false then
- Move("backward left")
- elseif D == true and A == true and W == false then
- Move("backward")
- elseif D == true and A == true and W == true then
- Move("stop")
- elseif D == false and A == false and W == true then
- Move("stop")
- elseif D == true and A == false and W == true then
- Move("right")
- elseif D == false and A == true and W == true then
- Move("left")
- end
- return
- end
- if D == true then
- if W == false and S == false and A == false then
- Move("right")
- elseif W == true and S == false and A == false then
- Move("forward right")
- elseif W == false and S == true and A == false then
- Move("backward right")
- elseif W == true and S == true and A == false then
- Move("right")
- elseif W == true and S == true and A == true then
- Move("stop")
- elseif W == false and S == false and A == true then
- Move("stop")
- elseif W == true and S == false and A == true then
- Move("forward")
- elseif W == false and S == true and A == true then
- Move("backward")
- end
- return
- end
- if A == true then
- if W == false and S == false and D == false then
- Move("left")
- elseif W == true and S == false and D == false then
- Move("forward left")
- elseif W == false and S == true and D == false then
- Move("backward left")
- elseif W == true and S == true and D == false then
- Move("left")
- elseif W == true and S == true and D == true then
- Move("stop")
- elseif W == false and S == false and D == true then
- Move("stop")
- elseif W == true and S == false and D == true then
- Move("forward")
- elseif W == false and S == true and D == true then
- Move("backward")
- end
- return
- end
- if W == false and S == false and A == false and D == false then
- Move("stop")
- return
- end
- end
- local function HandleMovementInput(input, gameprocessed)
- if input.KeyCode == Enum.KeyCode.W then
- W=true
- DetermineMovement()
- elseif input.KeyCode == Enum.KeyCode.S then
- S=true
- DetermineMovement()
- elseif input.KeyCode == Enum.KeyCode.A then
- A=true
- DetermineMovement()
- elseif input.KeyCode == Enum.KeyCode.D then
- D=true
- DetermineMovement()
- end
- end
- local function HandleMovementOutput(input, gameprocessed)
- if input.KeyCode == Enum.KeyCode.W then
- W=false
- DetermineMovement()
- elseif input.KeyCode == Enum.KeyCode.S then
- S=false
- DetermineMovement()
- elseif input.KeyCode == Enum.KeyCode.A then
- A=false
- DetermineMovement()
- elseif input.KeyCode == Enum.KeyCode.D then
- D=false
- DetermineMovement()
- end
- end
- local function HandleTouch(TouchPart)
- if TouchPart.Name == "JumpPart" then
- Character.HumanoidRootPart.Velocity = Character.HumanoidRootPart.Velocity + Vector3.new(0,100,0)
- end
- end
- for _, v in pairs(Character:GetChildren()) do
- if v:IsA("Part") or v:IsA("UnionOperation") then if v.Name ~= "HumanoidRootPart" then v.Massless = true end end
- end
- Character["RightFoot"].Touched:Connect(HandleTouch)
- Character["LeftFoot"].Touched:Connect(HandleTouch)
- UserInputService.InputBegan:Connect(HandleMovementInput)
- UserInputService.InputEnded:Connect(HandleMovementOutput)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement