Crawling Animation Acts Weirdly and Rotates

I’m developing a stand-alone movement system. Here is the code that I have so far:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

local player:Player = Players.LocalPlayer
local character:Model = player.Character or player.CharacterAppearanceLoaded:Wait()
local humanoid: Humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart: Part = character:WaitForChild("HumanoidRootPart")
local animator:Animator = humanoid:WaitForChild("Animator")

local currentStance = "Standing"
local currentAnimation = nil
local lowerStanceChain = {"Standing", "Crouching", "Crawling"}
local raiseStanceChain = {"Crawling", "Crouching", "Standing"}
local stanceInfoTable = {
	Standing = {
		HipHeight = 0,
		WalkSpeed = 16
	},
	Crouching = {
		HipHeight = -1.2,
		WalkSpeed = 8
	},
	Crawling = {
		HipHeight = 0,
		WalkSpeed = 5
	}
}

local rawAnimationTable = {
	CrawlingIdle = "rbxassetid://124203278710432",
	CrawlingMoving = "rbxassetid://89440579259821",
	CrouchingIdle = "rbxassetid://130867177244142",
	CrouchingMoving = "rbxassetid://131122474613098",
}

local loadedAnimationTable = {}

function InitializeAnimations()
	for name, id in pairs(rawAnimationTable) do
		local animation = Instance.new("Animation")
		animation.AnimationId = id
		loadedAnimationTable[name] = animator:LoadAnimation(animation)
	end
end

InitializeAnimations()

UserInputService.InputBegan:Connect(function(keycode, chatting)
	if chatting then return end
	if keycode.KeyCode == Enum.KeyCode.C then
		if currentStance == "Crawling" then return end
		
		currentStance  = lowerStanceChain[table.find(lowerStanceChain, currentStance)+1]
		
		if currentAnimation ~= nil then
			currentAnimation:Stop()
		end
		
		currentAnimation = loadedAnimationTable[currentStance.."Idle"]
		currentAnimation:Play()
	elseif keycode.KeyCode == Enum.KeyCode.X then
		if currentStance == "Standing" then return end
		
		currentStance  = raiseStanceChain[table.find(raiseStanceChain, currentStance)+1]

		if currentAnimation ~= nil then
			currentAnimation:Stop()
		end
		
		if currentStance ~= "Standing" then
			currentAnimation = loadedAnimationTable[currentStance.."Idle"]
			currentAnimation:Play()
		else
			currentAnimation = nil
		end
	end
	
	humanoid.HipHeight = stanceInfoTable[currentStance]["HipHeight"]
	humanoid.WalkSpeed = stanceInfoTable[currentStance]["WalkSpeed"]
end)

humanoid.Running:Connect(function(speed)
	if currentStance == "Standing" then return end
	print(speed)
	print(currentStance)
	print(currentAnimation)
	if speed > 0 and currentAnimation ~= loadedAnimationTable[currentStance.."Moving"]  then
		print("Changing Animation to Moving")
		currentAnimation:Stop()
		currentAnimation = loadedAnimationTable[currentStance.."Moving"]
		currentAnimation:Play()
	elseif speed == 0 or humanoidRootPart.Velocity.Magnitude == 0 and currentAnimation ~= loadedAnimationTable[currentStance.."Idle"] then
		print("Changing Animation to Idle")
		currentAnimation:Stop()
		currentAnimation = loadedAnimationTable[currentStance.."Idle"]
		currentAnimation:Play()
	end
end)

Attached are videos on how it should look vs. how it looks in-game(I’m using placeholder animations and these will be replaced in the real game along with being adjusted to the right height):


Does anyone have any idea how to stop my character from like rotating when moving in the "prone " state? All of the animations are set to Action Priority.

Are you saying you don’t want the character from flying? It looks like your animation is flying aswell so that is probably that is why.

The flying is fine, I just have to find the right hip height, which I can do later. The issue is that it seems like the torso rotates back towards the HRP when moving.

Your animation priority probably isn’t set to action. It’s being overridden by the walking animation.

Did you read the last part? I said that all of the animations were set to Action Priority.

Did you make sure that they are all set to looped?

That fixed it, thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.