local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local Camera = game.Workspace.CurrentCamera
local TS = game:GetService("TweenService")
local plr = game.Players.LocalPlayer
local Character = nil
local Humanoid = nil
local HumanoidRunningConnection = nil
--\\ State
local States = {}
States.Sprint = false
States.Crouch = false
States.Slide = false
--\\ Sprint and Walk Speed
local SprintSpeed = 23
local WalkSpeed = 16
--\\ Load Animations
local CrouchIdleAnim = "rbxassetid://8087634282"
local CrouchWalkAnim = "rbxassetid://8087642001"
local SlideAnim = "nil"
--\\ Field Of View settings
local function lerp(a, b, t)
return a * (1 - t) + (b * t)
end
local function SpringFov(Fov)
task.spawn(function()
local num = 0
while math.abs(num - Fov) > 0.01 do
num = lerp(num, Fov, 0.77)
local rec = num
Camera.FieldOfView += rec
RunService.RenderStepped:Wait()
end
end)
end
--\\ Sprinting
local function Sprint(ActionName, InputState, InputObject)
if not Character then return end
if not ActionName == "Sprint" then return end
if InputState == Enum.UserInputState.Begin then
States.Crouch = false
States.Sprint = true
CrouchIdleAnim:Stop()
CrouchWalkAnim:Stop()
--\\ Tweening
**Humanoid.WalkSpeed = SprintSpeed
UserInputService.InputBegan:Connect(function(key) --
if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
TS:Create(plr.Character.Humanoid, TweenInfo.new(10), {WalkSpeed = 23}):Play()
end
end)
UserInputService.InputEnded:Connect(function(key) --
if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
TS:Create(plr.Character.Humanoid, TweenInfo.new(10), {WalkSpeed = 16}):Play()
end
end)
SpringFov(SprintSpeed/6)
else
States.Sprint = false
Humanoid.WalkSpeed = WalkSpeed
SpringFov(-SprintSpeed/6)
end
end
--\\ Crouching
local function Crouch(ActionName, InputState, InputObject)
if not Character then return end
if States.Crouch == false then
States.Crouch = true
CrouchIdleAnim:Play()
Humanoid.WalkSpeed = 10
elseif States.Crouch == true then
States.Crouch = false
CrouchIdleAnim:Stop()
CrouchWalkAnim:Stop()
Humanoid.WalkSpeed = WalkSpeed
end
end
--\\ Sliding
local function Slide(ActionName, InputState, InputObject)
if not Character then return end
States.Crouch = false
States.Slide = true
CrouchIdleAnim:Stop()
CrouchWalkAnim:Stop()
local SlideVelocity = Instance.new("BodyVelocity")
SlideVelocity.MaxForce = Vector3.new(1,1,1) * 50000
SlideVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 50
-- R15
if Character:FindFirstChild("LowerTorso") then
SlideVelocity.Parent = Character.LowerTorso
end
--R6
if Character:FindFirstChild("Torso") then
SlideVelocity.Parent = Character.Torso
end
-- Start Sliding
SlideAnim:Play()
task.wait(1)
-- End Sliding
States.Slide = false
SlideVelocity:Destroy()
SlideAnim:Stop()
end
--\\ Crouch and Slide handler
local function CrouchAndSlide(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then else return end
if States.Sprint == false and States.Slide == false then
Crouch()
elseif States.Sprint == true and States.Slide == false then
Slide()
end
end
--\\ ContextActionService Input
ContextActionService:BindAction("Sprint", Sprint, false, Enum.KeyCode.LeftShift)
ContextActionService:BindAction("CrouchAndSlide", CrouchAndSlide, false, Enum.KeyCode.C, Enum.KeyCode.LeftControl)
local function HumanoidRunning(Speed)
if States.Crouch == true then
if Speed > 0 then
CrouchIdleAnim:Stop()
if not CrouchWalkAnim.IsPlaying then
CrouchWalkAnim:Play()
end
else
CrouchWalkAnim:Stop()
if not CrouchIdleAnim.IsPlaying then
CrouchIdleAnim:Play()
end
end
elseif States.Crouch == false then
CrouchIdleAnim:Stop()
CrouchWalkAnim:Stop()
end
end
game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
Character = char
Humanoid = Character:WaitForChild("Humanoid")
CrouchIdleAnim = Humanoid.Animator:LoadAnimation(script:WaitForChild("CrouchIdle"))
CrouchWalkAnim = Humanoid.Animator:LoadAnimation(script:WaitForChild("CrouchWalk"))
SlideAnim = Humanoid.Animator:LoadAnimation(script:WaitForChild("Slide"))
HumanoidRunningConnection = Humanoid.Running:Connect(HumanoidRunning)
end)
I know that this is completely inaccurate to the topic, but your weather system causes strain on the server.
You should add some more particle emitters and cull them according to the players camera. ALL OF THIS SHOULD HAPPEN ON THE CLIENT. In order to clone stuff and put them to the workspace FROM THE CLIENT, simply put the stuff to clone in ReplicatedStorage. I do not intend to ctiticize, I intend to help. Sorry for the irrelevant to the topic disturbance.
He basically means - when making a animation, or the animations for crouching, does the script move the playerās humanoidrootpart/character down automatically, or do we have to manually animate the character down.
No the animation does not move the HumanoidRootPart, and I donāt know the need to move it in the first placeā¦ if it is to move the Camera, Humanoid.CameraOffset is what will be used. And if it is about moving the body parts down, yes the Animation does that.
I would like to make a few of sugguestion for making things for the community or for anything open source in general.
The instructions on how to use this module is somewhat unclear. On initial use attempt, your users would not be aware that they must create a folder with animations and name the animations with specific names accordingly.
Expected: Animations provided with proper names and folder parented under the module or inscrutions telling users to give certain animations parented under a folder name āAnimationFolderā under ReplicatedStorage.
No basic API documentation was provided. Besides insurctions on how to initiate the module no instrcutions on how to use or what the module could do, although the method names are self-explainitory.
Expected: Some form of API documentation stating how or what the module can do. You can paste a bare bones list of methods with the comment section at the header for your module.
Example:
--[[
-- SETUP:
1. Place module within game.ReplicatedStorage.
2. Create a folder named "Animations" parented by game.ReplicatedStorage.
3. Place animations to game.ReplicatedStorage.Animations with the names: CrouchIdle, CrouchWalk, ProneIdle, ProneWalk, Slide
-- API:
local MovementProfile = require(game.ReplicatedStorage.MovementHandler.MovementHandler)
local movementHandle = MovementProfile:New({Player = game.Players.GiantDefender427})
movementHandle:Initiate()
movementHandle:StartSprinting()
movementHandle:StopSprinting()
movementHandle:StartCrouching()
movementHandle:StopCrouching()
movementHandle:StartProning()
movementHandle:StopProning()
]]
the instructions are unclear, and i am very confused as to what i am supposed to do with this movement handler. where are we even supposed to put everything??
Since a lot of you asked for this, I made uploaded a test place, you can download the test place here. Make sure to check out the files in ReplicatedStorage and StarterPlayerScripts.