A simple movement system with sprinting, crouching, and sliding!

Edit Feb ‘23: This is outdated and lacks a lot of security and possible improvements, while it might work good / ok i’d recommend adding a lot of server sanity checks and such — and it is not a good representation of my current ability

I got bored so I made a very simple movement system, if I update it in the future I will update this post and the available downloads!

What does it offer?

  • Crouching
  • Sprinting
  • Sliding

It is completely open source, and is free

Please do not claim it as your own and attempt to re-sell it for any value!

You can download it from the github repo here or the RBXL file, here Movement Test.rbxl (46.0 KB)

Report any bugs in the replies or contact me through discord or email, as-well as your own fixes or updates!

Discord: 651586414810759170 (userID) use this website to look up ID’s to accounts
Email: TheGamerZ3109@gmail.com

Have a good day!

Edit1: Video showcase

17 Likes

Nice! all of the animations look smooth.

3 Likes

how would I remove the sprinting?

Change the value of canSprint to false

local bools = { 
    canSprint = true,
}
1 Like

yeah, but what if I wanted to remove the feature completely

I havent opened this project in a while but you could comment out / delete the areas relating to sprinting [and removing the sprinting requirement line(s) in the sliding area]

i keep getting errors and stuff when i do that, here is my code

local plr = game:GetService(“Players”).LocalPlayer – player object
local char = plr.Character or plr.CharacterAdded:Wait() – character object
local humanoid = char:WaitForChild(“Humanoid”) – humanoid object

game.Workspace.CurrentCamera.HeadLocked = true – just set to false or comment out if this is causing issues in your game, it just sets the camera to follow the characters head object when for we ex. crouch

local UIS = game:GetService(“UserInputService”)

local crouchAnim = Instance.new(“Animation”) – animation for crouching, set the id to your own, or dont, idk at this point
crouchAnim.Parent = script
crouchAnim.Name = “CrouchAnimation”
crouchAnim.AnimationId = “rbxassetid://9701823161”

local slideAnim = Instance.new(“Animation”) – animation for sliding, set the id to your own, or dont, idk at this point
slideAnim.Parent = script
slideAnim.Name = “SlideAnimation”
slideAnim.AnimationId = “rbxassetid://9701872337”

local loadedAnims = { – animations
crouch = humanoid:LoadAnimation(crouchAnim),
slide = humanoid:LoadAnimation(slideAnim)
}

local bools = { – script wide booleans
crouching = false,
sliding = false,

canCrouch = true,
canSlide = false

}

local speeds = { – amount that we add or subtract for the event
crouching = 5,
sliding = 12
}

local keys = { – specified keys for each event, do NOT set any of them to the same key, it doesnt work, and im too lazy to fix it
crouching = Enum.KeyCode.C,
sliding = Enum.KeyCode.LeftShift
}

local maxSlideTime = 2 – max amount of time you can slide for before it auto stops you

function crouch(bool) – crouching animations
if bool then
loadedAnims.crouch:Play()
elseif not bool then
loadedAnims.crouch:Stop()
end
end

function slide(bool) – sliding animations
if bool then
loadedAnims.slide:Play()
elseif not bool then
loadedAnims.slide:Stop()
end
end

UIS.InputBegan:Connect(function(input, gameProcessedEvent) – on a keydown
if not gameProcessedEvent then – if we are actually playing the game and arent like, in the chat

    bools.canCrouch = false,  -- set the new boolean values

    elseif input.KeyCode == keys.crouching then -- if we pressed the crouching key

    if bools.canCrouch == false then return end -- checking if we can crouch
    if bools.crouching == true then return end -- checking if we arent already crouching (this shouldnt be needed but whatever)

    
    humanoid.WalkSpeed -= speeds.crouching -- take away the crouching speed
     bools.canCrouch, bools.crouching = false, true -- set the booleans

    crouch(true) -- send the function for animations

    elseif input.KeyCode == keys.sliding then

        if bools.crouching == true then return end -- make sure we arent crouching
        if bools.canSlide == true then return end -- just checking.. we can slide right?

        humanoid.WalkSpeed += speeds.sliding -- add the sliding speed to make them go brrrr

        bools.canCrouch, bools.canSlide, bools.sliding, bools.crouching,  = false, false, true, false -- set *a lot* booleans

        slide(true) -- send the animation event

        while task.wait(maxSlideTime) do -- wait until the max slide time is up
  		if bools.sliding == true then -- if we didnt already stop sliding

                humanoid.WalkSpeed -= speeds.sliding -- remove the sliding speed

                 bools.canCrouch, bools.canSlide, bools.sliding, bools.crouching, = true, false, false, false -- set *a lot* booleans

                slide(false) -- animation function

  			break -- break the loop so that we dont keep checking
  		end
  	end

	end

end

end)

UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then

    bools.canCrouch = true -- set booleans
  	
    elseif input.KeyCode == keys.crouching then -- did we stop pressing the crouch key

    if bools.canCrouch == true then return end -- double checks with crouching idk how to explain this
    if bools.crouching == false then return end -- just making sure we are crouchign

    humanoid.WalkSpeed += speeds.crouching -- give them their speed back
    bools.canCrouch, bools.crouching = true, false -- set bools

    crouch(false) -- fire animation function

elseif input.KeyCode == keys.sliding then -- did we stop pressing the sliding key

        if bools.crouching == true then return end -- we arent crouching
        if bools.canSlide == true then return end -- double check thing again xd
        if bools.sliding == false then return end -- making sure we can slide
        
        humanoid.WalkSpeed -= speeds.sliding -- give them the speed back

        bools.canCrouch, bools.canSlide, bools.sliding, bools.crouching = true, false, false, false -- set *a lot* booleans

        slide(false) -- fire the animation function
   end

end

end)

1 Like