MovementDirection just saying 0,0,0

ive looked everywhere and nothing answers my problem, the Vector3 being returned is 0,0,0 and i have no idea why

local Services = {
	["UserInputService"] = game:GetService("UserInputService"),
	["ContextActionService"] =  game:GetService("ContextActionService"),
	["Debris"] = game:GetService("Debris"),
	["TweenService"] = game:GetService("TweenService")
}

local function cardinalConvert(dir)
	local angle = math.atan2(dir.X, -dir.Z)
	local quarterTurn = math.pi / 2
	angle = -math.round(angle / quarterTurn) * quarterTurn

	local newX = -math.sin(angle)
	local newZ = -math.cos(angle)
	if math.abs(newX) <= 1e-10 then newX = 0 end
	if math.abs(newZ) <= 1e-10 then newZ = 0 end
	return Vector3.new(newX, 0, newZ)
end

local PlayerStuffs = {
	["Camera"] = workspace.CurrentCamera,
	["LocalPlayer"] = game:GetService("Players").LocalPlayer,
	["Humanoid"] = game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid"),
	["MovementDirection"] = game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").MoveDirection,
	--["DotProductOfSideMovementDirection"] = math.round(game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").MoveDirection:Dot(game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").RootPart.CFrame.RightVector)),
	--["DotProductOfMovementDirection"] = math.round(game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").MoveDirection:Dot(game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").RootPart.CFrame.LookVector))
}

local Times = {
	["DashTime"] = 20,
	["DashCooldownTime"] = 0.5
}

local CounterVaribles = {
	["DashStrength"] = 150,
	["DashCooldown"] = false
}

local function StartCooldown()
	CounterVaribles.DashCooldown = true
	task.delay(Times.DashCooldownTime, function()
		CounterVaribles.DashCooldown = false
	end)
end

local function Dash(actionName, inputState, _inputObject)
	if actionName == "Dash" and inputState == Enum.UserInputState.Begin and CounterVaribles.DashCooldown == false then
		if PlayerStuffs.Humanoid.RootPart.AssemblyLinearVelocity.Magnitude >= 0.01 then--and PlayerStuffs.Humanoid.FloorMaterial ~= Enum.Material.Air then
			StartCooldown()
			local force = Instance.new("LinearVelocity", PlayerStuffs.Humanoid.RootPart:WaitForChild("RootAttachment"))
			Services.Debris:AddItem(force, Times.DashTime)
			force.Attachment0 = PlayerStuffs.Humanoid.RootPart:WaitForChild("RootAttachment")
			force.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
			force.MaxForce = math.huge
			force.PrimaryTangentAxis = Vector3.new(1, 0, 0)
			force.SecondaryTangentAxis = Vector3.new(0, 0, 1)
			force.VelocityConstraintMode =Enum.VelocityConstraintMode.Plane
			print(PlayerStuffs.MovementDirection)
			force.PlaneVelocity = Vector2.new(PlayerStuffs.MovementDirection.X * CounterVaribles.DashStrength, PlayerStuffs.MovementDirection.Z * CounterVaribles.DashStrength)
			local speedTween = Services.TweenService:Create(force, TweenInfo.new(Times.DashTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {PlaneVelocity = Vector2.new(0,0)})
			speedTween:Play()
		end
	end
end

Services.UserInputService.InputBegan:Connect(function(input:InputObject, gameProcessedEvent:boolean)
	if gameProcessedEvent then return end

	Services.ContextActionService:BindActionAtPriority("Dash", Dash, false, 0, Enum.KeyCode.Q)
end)

because you assign the movedirection to a variable only when the script starts so it doesnt update, i would recommend just doing PlayerStuffs.Humanoid.MoveDirection

1 Like

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