How to play animations with directional dashing, please help im lost

  1. What do you want to achieve? Keep it simple and clear!
    I made directional dashing with move Direction, and i want to make it so if you’re mostly going forward (Holding AW for example), character plays the forward roll animation, and if you’re going backwards, you’re going to play backward roll animation.

  2. What is the issue? Include screenshots / videos if possible!
    I have absolutely no idea how to do this, that’s the issue.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried to take a look at others examples of code in devforum, and haven’t found anything.

uis.InputBegan:Connect(function(input,isTyping)
	if isTyping then return end
	if input.KeyCode == Enum.KeyCode.Q and dashDeb == false then
		
		local hum = char:FindFirstChild("Humanoid")
		local humRoot = char:FindFirstChild("HumanoidRootPart")
		
		dashDeb = true

		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {char,workspace.Baseplate}
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude

		local rayResult = workspace:Raycast(humRoot.Position,hum.MoveDirection * vars.DASH_DISTANCE,raycastParams)
		local rayPos
		if rayResult then
			local part = rayResult.Instance
			if part.CanCollide == true then
				rayPos = rayResult.Position
			else
				rayPos = (humRoot.CFrame + (hum.MoveDirection * vars.DASH_DISTANCE)).Position
			end
		else
			rayPos = (humRoot.CFrame + (hum.MoveDirection * vars.DASH_DISTANCE)).Position
		end

		local mover = Instance.new("BodyPosition",humRoot)
		mover.MaxForce = Vector3.new(9999999,9999999,9999999)
		mover.D = 100
		mover.P = 1000
		mover.Position = rayPos
		debris:AddItem(mover,0.3)

		local gyro = Instance.new("BodyGyro",humRoot)
		gyro.MaxTorque = Vector3.new(9999999,9999999,9999999)
		gyro.D = 100
		gyro.P = 1000
		gyro.CFrame = humRoot.CFrame
		debris:AddItem(gyro,0.3)

		spawn(function()
			wait(vars.DASH_CD)
			dashDeb = false
		end)
	end
end)

The code is working fine, it dashes me exactly where i want to go, i’m just struggling with animations.

1 Like

This should work:

uis.InputBegan:Connect(function(input,isTyping)
	if isTyping then return end
	if input.KeyCode == Enum.KeyCode.Q and dashDeb == false then
		
		local hum = char:FindFirstChild("Humanoid")
		local humRoot = char:FindFirstChild("HumanoidRootPart")

local animation = Instance.new("Animation",hum)
animation.AnimationId = "rbxassetid://0" -- put your animation id in here

local animationTrack = hum:LoadAnimation(animation)
		
		dashDeb = true

		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {char,workspace.Baseplate}
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude

		local rayResult = workspace:Raycast(humRoot.Position,hum.MoveDirection * vars.DASH_DISTANCE,raycastParams)
		local rayPos
		if rayResult then
			local part = rayResult.Instance
			if part.CanCollide == true then
				rayPos = rayResult.Position
			else
				rayPos = (humRoot.CFrame + (hum.MoveDirection * vars.DASH_DISTANCE)).Position
			end
		else
			rayPos = (humRoot.CFrame + (hum.MoveDirection * vars.DASH_DISTANCE)).Position
		end

		local mover = Instance.new("BodyPosition",humRoot)
		mover.MaxForce = Vector3.new(9999999,9999999,9999999)
		mover.D = 100
		mover.P = 1000
		mover.Position = rayPos
		debris:AddItem(mover,0.3)

		local gyro = Instance.new("BodyGyro",humRoot)
		gyro.MaxTorque = Vector3.new(9999999,9999999,9999999)
		gyro.D = 100
		gyro.P = 1000
		gyro.CFrame = humRoot.CFrame
		debris:AddItem(gyro,0.3)

animationTrack:Play()

		spawn(function()
			wait(vars.DASH_CD)
			dashDeb = false
		end)
	end
end)
2 Likes
local function getMovementDirection(humanoid)

	if forward ~= 0 then
		
		if forward == -1 then
			TrackBack:Play()
			
		else
			TrackFront:Play()
		end
		return
	end
	
	if right ~= 0 then
		
		if right == -1 then
			TrackLeft:Play()
			
		else
			TrackRight:Play()
		end
		return
	end
end

-- dashing
uis.InputBegan:Connect(function(input,isTyping)
	if isTyping then return end
	if input.KeyCode == Enum.KeyCode.Q and dashDeb == false then

		dashDeb = true

		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {char,workspace.Baseplate}
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude

		local rayResult = workspace:Raycast(humRoot.Position,hum.MoveDirection * vars.DASH_DISTANCE,raycastParams)
		local rayPos
		if rayResult then
			local part = rayResult.Instance
			if part.CanCollide == true then
				rayPos = rayResult.Position
			else
				rayPos = (humRoot.CFrame + (hum.MoveDirection * vars.DASH_DISTANCE)).Position
			end
		else
			rayPos = (humRoot.CFrame + (hum.MoveDirection * vars.DASH_DISTANCE)).Position
		end
		
		print(hum.MoveDirection)
		getMovementDirection(hum)
		
		local RigAttachment = humRoot:FindFirstChild("RootAttachment")
		
		local mover = Instance.new("AlignPosition",humRoot)
		mover.Mode = Enum.PositionAlignmentMode.OneAttachment
		mover.Attachment0 = RigAttachment
		mover.MaxForce = math.huge
		mover.Position = rayPos
		debris:AddItem(mover,0.5)

		local gyro = Instance.new("AlignOrientation",humRoot)
		gyro.Mode = Enum.OrientationAlignmentMode.OneAttachment
		gyro.Attachment0 = RigAttachment
		gyro.MaxTorque = math.huge
		gyro.Responsiveness = 50
		
		local lookVector = currCamera.CFrame.LookVector
		local lookvec_ = Vector3.new(lookVector.X, 0, lookVector.Z).Unit
		gyro.CFrame = CFrame.new(Vector3.new(0,0,0), lookvec_)
		debris:AddItem(gyro,0.5)

		spawn(function()
			wait(vars.DASH_CD)
			dashDeb = false
		end)
	end
end)

function RightAction(ActionName, InputState, InputObject)
	if InputState == Enum.UserInputState.Begin then
		right = 1
	else 
		right = 0
	end
	return Enum.ContextActionResult.Pass
end
function LeftAction(ActionName, InputState, InputObject)
	if InputState == Enum.UserInputState.Begin then
		right = -1
	else 
		right = 0
	end
	return Enum.ContextActionResult.Pass
end
function BackAction(ActionName, InputState, InputObject)
	if InputState == Enum.UserInputState.Begin then
		forward = -1
	else 
		forward = 0
	end
	return Enum.ContextActionResult.Pass
end
function ForwardAction(ActionName, InputState, InputObject)
	if InputState == Enum.UserInputState.Begin then
		forward = 1
	else 
		forward = 0
	end
	return Enum.ContextActionResult.Pass
end
ContextActionService:BindAction("Forward", ForwardAction, true, Enum.KeyCode.W)
ContextActionService:BindAction("Back", BackAction, true, Enum.KeyCode.S)
ContextActionService:BindAction("Right", RightAction, true, Enum.KeyCode.D)
ContextActionService:BindAction("Left", LeftAction, true, Enum.KeyCode.A)

I did it this way.
This is the result:

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