Animation breaks after force applied

I’m making a dungeon crawler RPG type game, with custom characters. And I’ve
ran into an issue with the attacking animation.

What do I want to achieve?
I have a custom character, and I want to make it so when it slashes, it moves forward a bit.
Sorta like this:

What is the issue?
Whenever the character moves forward, the animation cancels.

Example:

This is what the animation looks like:

What solutions have I tried so far?
I’ve tried VectorForce, BodyVelocity, CFrame, and ApplyImpulse. All do the same thing.

Here is my code:

if not (humanoid.MoveDirection.Magnitude > 0) then
local Force = 50
								char.PrimaryPart:ApplyImpulse(char.PrimaryPart.CFrame.LookVector * char.PrimaryPart.AssemblyMass * Force)
end

local punchAnimation = humanoid.Animator:LoadAnimation(script:FindFirstChild("Punch" .. Combo))
punchAnimation:Play()

I also tested this with a normal Roblox character and it works fine.
Here’s the video:

Here’s my custom character’s parts and Humanoid properties:


Screenshot 2024-02-10 162643

Any support would be great.
Thanks!

-Mattc04

I think you have to set the animation priority higher than the walk animation

The attack animation priority is Action.
while the walk animation priority is Movement.

Here’s the walk animation script if you’re interested:

local idleAnim = script.Parent.Animations:WaitForChild("IdleNEW")
local idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)

humanoid.Running:Connect(function(speed)
	if speed > 0 and speed < 17 then
		if not walkAnimTrack.IsPlaying then
			stopAllAnimations()
			walkAnimTrack:Play()
		end
	elseif speed > 0 and speed > 17 then
		if not RunAnimTrack.IsPlaying then
			stopAllAnimations()
			RunAnimTrack:Play()
		end
	else
		if walkAnimTrack.isPlaying then
			stopAllAnimations()
			idleAnimTrack:Play()
		end
	end
end)
function stopAllAnimations()
	for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do
		v:Stop()
	end
end

Just fixed it! I used TweenService instead of vectorForce or ApplyImpulse.

--Tween
local distance = 2
local tweenDuraton = .25
local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(tweenDuraton, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tween = TweenService:Create(char.HumanoidRootPart, tweenInfo, {CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0, 0, -distance) })
							
humanoid.WalkSpeed = 2
game.ReplicatedStorage.Events.Server.ServerAttacks:WaitForChild("ClawEvent"):FireServer(Combo, punchDamage)
if (humanoid.MoveDirection.Magnitude == 0) then
	tween:Play()
end

Btw I moved animation to server side for animationKeyframe

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