Movement system

hi i edited a directional movement system to make uhh idk anyways the person who made the 4 way directional movement was called devdump i think

the thing includes
crouching with raycast
directional movement totally mine
idk just more

script

-- Made right after my birthday!
local InputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Workspase = game:GetService("Workspace")

local Resources = script:WaitForChild("Resources")
local Anims = Resources:WaitForChild("Animations")
local Sounds = Resources:WaitForChild("Sounds")
local Values = Resources:WaitForChild("Values")

local Character = script.Parent
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")

local TouchTable = {}
for Index, Part in ipairs(Workspase:WaitForChild("Touchable"):GetChildren()) do
	table.insert(TouchTable, Part)
end

local Settings = {
	Character = {
		WalkSpeed = {
			["Default"] = 14,
			["Forward"] = 14,
			["Left"] = 12,
			["Right"] = 12,
			["Back"] = 10,
			["Crouch"] = 6,
		},
		MaxSlopeAngle = 48,
		JumpHeight = 4.88,
	},
	Script = {
		Crouch = {
			CrouchingAllowed = true,
			CrouchingToggle = false,
		},
		WallHittingAllowed = true,
		JumpingAllowed = true,
		RunningAllowed = true,
		
		SoundsAllowed = true,
	},
}

Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Default
Humanoid.JumpHeight = Settings.Character.JumpHeight
Humanoid.MaxSlopeAngle = Settings.Character.MaxSlopeAngle

local AnimationsTable = {
	["Idle"] = Humanoid:LoadAnimation(Anims.Idle),
	["Forward"] = Humanoid:LoadAnimation(Anims.WalkForward),
	["Right"] = Humanoid:LoadAnimation(Anims.WalkRight),
	["Left"] = Humanoid:LoadAnimation(Anims.WalkLeft),
	["Crouch"] = Humanoid:LoadAnimation(Anims.Crouch),
	["Move"] = Humanoid:LoadAnimation(Anims.CrouchMove),
	["Wall"] = Humanoid:LoadAnimation(Anims.Ouch),
	["Run"] = Humanoid:LoadAnimation(Anims.Run),
	["Jump"] = Humanoid:LoadAnimation(Anims.Jump),
	["Fall"] = Humanoid:LoadAnimation(Anims.Falling),
	["Land"] = Humanoid:LoadAnimation(Anims.Land),
	["Climb"] = Humanoid:LoadAnimation(Anims.Climb),
}

for Index, Animation in pairs(AnimationsTable) do
	Animation:Play(0, 0.001, 0)
end

local function PlaySound(Sound) -- Sounds play on the client for now. \\
	local New = Sound:Clone()
	New.Parent = HumanoidRootPart
	New:Play()
	
	New.Ended:Connect(function()
		New:Destroy()
	end)
end

RunService.RenderStepped:Connect(function()
	if Values.CanMove.Value then
		local DirectionOfMovement = HumanoidRootPart.CFrame:VectorToObjectSpace(HumanoidRootPart.AssemblyLinearVelocity)

		local Forward = math.abs(math.clamp(DirectionOfMovement.Z / Humanoid.WalkSpeed, -1, -0.001))
		local Backward = math.abs(math.clamp(DirectionOfMovement.Z / Humanoid.WalkSpeed, 0.001, 1))
		local Right = math.abs(math.clamp(DirectionOfMovement.X / Humanoid.WalkSpeed, 0.001, 1))
		local Left = math.abs(math.clamp(DirectionOfMovement.X / Humanoid.WalkSpeed, -1, -0.001))
		local SpeedUnit = (DirectionOfMovement.Magnitude / Humanoid.WalkSpeed)

		if not Values.Crouching.Value then
			if DirectionOfMovement.Z / Humanoid.WalkSpeed < 0.1 then
				AnimationsTable.Forward:AdjustWeight(Forward)
				AnimationsTable.Right:AdjustWeight(Right)
				AnimationsTable.Left:AdjustWeight(Left)
				AnimationsTable.Forward:AdjustSpeed(SpeedUnit)
				AnimationsTable.Right:AdjustSpeed(SpeedUnit)
				AnimationsTable.Left:AdjustSpeed(SpeedUnit)
				AnimationsTable.Idle:AdjustWeight(0.001)
			else
				AnimationsTable.Forward:AdjustWeight(Backward)
				AnimationsTable.Right:AdjustWeight(Left)
				AnimationsTable.Left:AdjustWeight(Right)
				AnimationsTable.Forward:AdjustSpeed(SpeedUnit * -1)
				AnimationsTable.Right:AdjustSpeed(SpeedUnit * -1)
				AnimationsTable.Left:AdjustSpeed(SpeedUnit * -1)
				AnimationsTable.Idle:AdjustWeight(0.001)
			end
			if DirectionOfMovement.Magnitude < 0.1 then
				AnimationsTable.Idle:AdjustWeight(1)
				AnimationsTable.Left:AdjustWeight(0.001)
				AnimationsTable.Right:AdjustWeight(0.001)
				AnimationsTable.Forward:AdjustWeight(0.001)
				AnimationsTable.Forward:AdjustSpeed(SpeedUnit * -1)
				AnimationsTable.Right:AdjustSpeed(SpeedUnit * -1)
				AnimationsTable.Left:AdjustSpeed(SpeedUnit * -1)
			end
			AnimationsTable.Move:AdjustWeight(0.001)
			AnimationsTable.Crouch:AdjustWeight(0.001)
		else
			if DirectionOfMovement.Z / Humanoid.WalkSpeed < 0.1 then
				AnimationsTable.Move:AdjustWeight(1)
				AnimationsTable.Move:AdjustSpeed(SpeedUnit)
				AnimationsTable.Crouch:AdjustWeight(0.001)
			else
				AnimationsTable.Move:AdjustWeight(1)
				AnimationsTable.Move:AdjustSpeed(SpeedUnit * -1)
				AnimationsTable.Crouch:AdjustWeight(0.001)
			end
			if DirectionOfMovement.Magnitude < 0.1 then
				AnimationsTable.Crouch:AdjustWeight(1)
				AnimationsTable.Move:AdjustWeight(0.001)
				AnimationsTable.Move:AdjustSpeed(SpeedUnit * -1)
			end
			AnimationsTable.Idle:AdjustWeight(0.001)
			AnimationsTable.Left:AdjustWeight(0.001)
			AnimationsTable.Right:AdjustWeight(0.001)
			AnimationsTable.Forward:AdjustWeight(0.001)
		end
	else
		AnimationsTable.Idle:AdjustWeight(0.001)
		AnimationsTable.Left:AdjustWeight(0.001)
		AnimationsTable.Right:AdjustWeight(0.001)
		AnimationsTable.Forward:AdjustWeight(0.001)
		AnimationsTable.Move:AdjustWeight(0.001)
		AnimationsTable.Crouch:AdjustWeight(0.001)
	end

	-- Top-tier scripting below. \\
	if (Humanoid.MoveDirection:Dot(HumanoidRootPart.CFrame.LookVector) > 0.45) then
		Values.Directions.Forward.Value = true
	else
		Values.Directions.Forward.Value = false
	end

	if (Humanoid.MoveDirection:Dot(-HumanoidRootPart.CFrame.RightVector) > 0.45) then
		Values.Directions.Left.Value = true
	else
		Values.Directions.Left.Value = false
	end

	if (Humanoid.MoveDirection:Dot(HumanoidRootPart.CFrame.RightVector) > 0.45) then
		Values.Directions.Right.Value = true
	else
		Values.Directions.Right.Value = false
	end

	if (Humanoid.MoveDirection:Dot(-HumanoidRootPart.CFrame.LookVector) > 0.45) then
		Values.Directions.Backward.Value = true
	else
		Values.Directions.Backward.Value = false
	end

	if Values.Directions.Forward.Value then
		Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Forward
	end

	if Values.Directions.Left.Value then
		Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Left
	end

	if Values.Directions.Right.Value then
		Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Right
	end

	if Values.Directions.Backward.Value then
		Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Back
	end
end)

if Settings.Script.Crouch.CrouchingAllowed then
	InputService.InputBegan:Connect(function(Input, Chat)
		if Chat then
			return
		end

		if Input.KeyCode == Enum.KeyCode.C or Input.KeyCode == Enum.KeyCode.LeftControl then
			if not Values.Crouching.Value then
				if Settings.Script.SoundsAllowed then
					PlaySound(Sounds.CrouchStart)
				end
				
				Values.Crouching.Value = true
				Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Crouch
				Humanoid.JumpHeight = 0
			else
				if Settings.Script.Crouch.CrouchingToggle then
					local RaycastParam = RaycastParams.new()
					RaycastParam.FilterType = Enum.RaycastFilterType.Exclude
					RaycastParam.FilterDescendantsInstances = {Character}
					local RaycastResults = Workspase:Raycast(HumanoidRootPart.Position, Vector3.new(0, 3, 0), RaycastParam)

					if not (RaycastResults and RaycastResults.Instance.CanCollide) then
						if Settings.Script.SoundsAllowed then
							PlaySound(Sounds.CrouchEnd)
						end
						
						Values.Crouching.Value = false
						Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Default
						Humanoid.JumpHeight = Settings.Character.JumpHeight
					end
				end
			end
		end
	end)

	InputService.InputEnded:Connect(function(Input, Chat)
		if Chat then
			return
		end

		if Input.KeyCode == Enum.KeyCode.C or Input.KeyCode == Enum.KeyCode.LeftControl then
			if not Settings.Script.Crouch.CrouchingToggle then
				local RaycastParam = RaycastParams.new()
				RaycastParam.FilterType = Enum.RaycastFilterType.Exclude
				RaycastParam.FilterDescendantsInstances = {Character}
				local RaycastResults = Workspase:Raycast(HumanoidRootPart.Position, Vector3.new(0, 3, 0), RaycastParam)

				if not (RaycastResults and RaycastResults.Instance.CanCollide) then
					if Settings.Script.SoundsAllowed then
						PlaySound(Sounds.CrouchEnd)
					end
					
					Values.Crouching.Value = false
					Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Default
					Humanoid.JumpHeight = Settings.Character.JumpHeight
				else
					coroutine.wrap(function()
						repeat
							task.wait(0.08)
							local NewResults = Workspase:Raycast(HumanoidRootPart.Position, Vector3.new(0, 3, 0), RaycastParam)
						until not (NewResults and NewResults.Instance.CanCollide)
						
						if Settings.Script.SoundsAllowed then
							PlaySound(Sounds.CrouchEnd)
						end
						
						Values.Crouching.Value = false
						Humanoid.WalkSpeed = Settings.Character.WalkSpeed.Default
						Humanoid.JumpHeight = Settings.Character.JumpHeight
					end)()
				end
			end
		end
	end)
end

if Settings.Script.JumpingAllowed then
	Humanoid.StateChanged:Connect(function(Old, New)
		if New == Enum.HumanoidStateType.Jumping then
			if not Values.Crouching.Value then
				if Settings.Script.SoundsAllowed then
					PlaySound(Sounds.JumpStart)
				end
				
				Values.Jumping.Value = true
				Values.CanMove.Value = false
				AnimationsTable.Jump:Play()
				AnimationsTable.Jump:AdjustWeight(1)
				AnimationsTable.Land:AdjustWeight(0.001)
			end
		elseif New == Enum.HumanoidStateType.Freefall then
			if Settings.Script.SoundsAllowed then
				PlaySound(Sounds.JumpMid)
			end
			
			Values.CanMove.Value = false
			AnimationsTable.Fall:AdjustWeight(1)
		elseif New == Enum.HumanoidStateType.Landed then
			if Settings.Script.SoundsAllowed then
				PlaySound(Sounds.JumpEnd)
			end
			
			AnimationsTable.Land:Play()
			AnimationsTable.Land:AdjustWeight(1)
			AnimationsTable.Jump:AdjustWeight(0.001)
			AnimationsTable.Fall:AdjustWeight(0.001)
			Values.CanMove.Value = true
			Values.Jumping.Value = false
		end
	end)
end

--[[ I will fix this never.
if Settings.Script.WallHittingAllowed then
	HumanoidRootPart.Touched:Connect(function(HitPart)
		if not (Values.Jumping.Value and Values.Crouching.Value and Values.TouchingWall.Value) then
			if table.find(TouchTable, HitPart) then
				if HitPart:IsA("Part") then
					local Magnitude = (HumanoidRootPart.Position - HitPart.Position).Magnitude
					if Magnitude > 0.1 then
						if HumanoidRootPart.Velocity.Magnitude > 12 then
							if Settings.Script.SoundsAllowed then
								PlaySound(Sounds.WallHit)
							end
							
							Values.TouchingWall.Value = true
							AnimationsTable.Wall:Play()
							AnimationsTable.Wall:AdjustWeight(1)
							AnimationsTable.Wall.Stopped:Connect(function()
								AnimationsTable.Wall:AdjustWeight(0.001)
								Values.TouchingWall.Value = false
							end)
						end
					end
				end
			end
		end
	end)
end
-]]

Animate.rbxm (6.5 KB)

also i wonder if i will ever get banned from devforum

12 Likes

if i wree yopu i wiuld get the model or the file since theres other stuff that you need for the thing to work

btw i think i forgot some stuff and its a bit incomplete but ehh you can do it yourself

You can’t share animations with others on Roblox, unfortunately. You’d have to save the animation from the animation editor then provide it with the script for users to upload, to get their own animationid.

2 Likes

You can use this plugin by kylethornton: https://create.roblox.com/marketplace/asset/2537608092/Animation-Spoofer-V2-Update . Just paste the animationID in the plugin window and click “convert”.

Oh wow, never heard of that plugin. That would have been a lifesaver so long ago… ugh. Anyway, it looks like he cleared the animationids in the animations anyways, so we’ll have to see if OP updates it.

1 Like