I’m currently trying to use AlignPosition for dashing, as it seems the most reliable, in terms of distance.
There’s a slight problem though, and that’s when i dash, it moves the character slightly up, which can cause some unwanted behaviour.
This is the function itself:
function MovementController:Dash()
local playerCharacter = self.Owner.Character
local rootPart = playerCharacter:FindFirstChild("HumanoidRootPart")
local humanoid = playerCharacter:FindFirstChild("Humanoid")
local dashDirection = humanoid.MoveDirection
local maxDashDistance = self.DashingDistance
if humanoid.MoveDirection.Magnitude < 0.1 then
dashDirection = rootPart.CFrame.LookVector
end
dashDirection = Vector3.new(dashDirection.X, 0, dashDirection.Z).Unit
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace.Map}
raycastParams.FilterType = Enum.RaycastFilterType.Include
local raycastResult = workspace:Raycast(rootPart.Position, dashDirection * maxDashDistance, raycastParams)
if raycastResult then
maxDashDistance = (rootPart.Position - raycastResult.Position).Magnitude - 2
end
local alignPosition = Instance.new("AlignPosition")
alignPosition.ApplyAtCenterOfMass = true
alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
alignPosition.Attachment0 = rootPart:FindFirstChild("RootAttachment")
alignPosition.MaxForce = math.huge
alignPosition.Responsiveness = 200
local targetPosition = rootPart.Position + dashDirection * maxDashDistance
targetPosition = Vector3.new(targetPosition.X, rootPart.Position.Y, targetPosition.Z)
alignPosition.Position = targetPosition
alignPosition.Parent = rootPart
task.wait(0.2)
alignPosition:Destroy()
end
I made sure to nullify the y coordinate of the dashDirection vector
dashDirection = Vector3.new(dashDirection.X, 0, dashDirection.Z).Unit
And i use the rootpart’s y position as the target position:
targetPosition = Vector3.new(targetPosition.X, rootPart.Position.Y, targetPosition.Z)
Any idea why it’s happening?