Dash Using Movedirection Doesn't Work With Animation Because Movedirection Relies On Torso Rotation

I’m working on a dash script that relies on movedirection, I want to have the dash to not change its intended directions and angles(right, left, front and back) when animating the player in the dash.

The issue is when i animate the torso’s rotation, the movedirection changes according to it.


as you see, the torso’s rotation is changed in the front dash, but its not in the side dash.

something i did is to duplicate the torso and have the dash use the movedirection on the duplicated torso, while the original torso stays animated, however this makes the player not able to turn.
i also tried setting the humanoidrootpart massless false and rootpriority to 0, however this made no difference.

local function dash(dash, dashDirection) 
	gameSettings.RotationType = Enum.RotationType.CameraRelative

	-- Determine the duration and start/end speeds based on what dash it is
	local dashStartSpeed 
	local dashDuration 
	local dashEndSpeed 
	if dash == "FrontDash" then
		dashStartSpeed = 55
		dashDuration = 1
		dashEndSpeed = 30
	elseif dash == "SideDash" then
		dashStartSpeed = 60
		dashDuration = 0.40
		dashEndSpeed = 10

	elseif dash == "BackDash" then
		dashStartSpeed = 55
		dashDuration = 0.70
		dashEndSpeed = 30
	end

	local increment = ((dashEndSpeed- dashStartSpeed) / (dashDuration* 60)) * 2 -- Simple velocity calculation

	local linearVelocity = Instance.new("LinearVelocity")
	local attachment0 = Instance.new("Attachment")
	linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World

	linearVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
	linearVelocity.MaxAxesForce = Vector3.new(math.huge, 0, math.huge)

	linearVelocity.Attachment0 = attachment0
	linearVelocity.Enabled = true
	linearVelocity.Parent = torso
	attachment0.Parent = torso

	local directionalForce
	if dash == "FrontDash" or dashDirection == "Right" then
		directionalForce = 1 -- Imagine that the player position is a graph/2d coordinate, if all values => 0 then its either going up or left
	elseif dash == "BackDash" or dashDirection == "Left" then
		directionalForce = -1 -- And if its all =< 0 then its either going down or left (this works because the dash only changes X or Y value, not both at once)
	end

	if dash == "FrontDash" or dash == "BackDash" then
		for i = dashStartSpeed, dashEndSpeed, increment do
			local MoveDirection = torso.CFrame.LookVector
			if humanoid:GetState() == Enum.HumanoidStateType.Jumping or humanoid:GetState() == Enum.HumanoidStateType.Freefall or humanoid:GetState() == Enum.HumanoidStateType.FallingDown then
				linearVelocity.VectorVelocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce) / 1.25 -- So that you dash less further in air
				wait()
			else 
				linearVelocity.VectorVelocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce) 
				wait()
			end
		end

	elseif dashDirection == "Left" or dashDirection == "Right" then
		for i = dashStartSpeed, dashEndSpeed, increment do
			local MoveDirection = torso.CFrame.RightVector
			if humanoid:GetState() == Enum.HumanoidStateType.Jumping or humanoid:GetState() == Enum.HumanoidStateType.Freefall or humanoid:GetState() == Enum.HumanoidStateType.FallingDown then
				linearVelocity.VectorVelocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce) / 1.25 -- So that you dash less further in air
				wait()
			else 
				linearVelocity.VectorVelocity = Vector3.new(MoveDirection.X * i * directionalForce, 0, MoveDirection.Z * i * directionalForce) 
				wait()
			end
		end
	end

	linearVelocity:Destroy()
	attachment0:Destroy()

	gameSettings.RotationType = Enum.RotationType.MovementRelative
end

quickly solved when i used humanoidrootpart for the moveDirection instead of torso.

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