Character Root Part Tween/Dash Towards Camera's lookVector

I’m Trying To Make A Dash Or Tween System That Tweens The Character Humanoid Root Part Towards Where The Camera’s Facing

I Have No Idea How I Would Do This Except I Know I Would Need The Current Camera lookVector

This Is My Script:

script.Parent.Dash.OnServerEvent:Connect(function(plr)
	local RootPart = plr.Character:WaitForChild("HumanoidRootPart")
	local Trail = game.ReplicatedStorage.Trail:Clone()
	Trail.Parent = RootPart
	Trail.CFrame = RootPart.CFrame
	local Weld = Instance.new("Motor6D", Trail)
	Weld.Part0 = RootPart
	Weld.Part1 = Trail
	local Goal = {}
	Goal.CFrame = RootPart.CFrame + RootPart.CFrame.lookVector * 25 + Vector3.new(0,0.05,0)
	
	local tweenInfo = TweenInfo.new(0.35, Enum.EasingStyle.Linear)
	
	TweenService:Create(RootPart, tweenInfo, Goal):Play()
	wait(0.375)
	Trail:Destroy()
end)

Here’s Where I Would Need To Modify Tween’s Goal.

	Goal.CFrame = RootPart.CFrame + RootPart.CFrame.lookVector * 25 + Vector3.new(0,0.05,0)

Could Anybody Help Me Out Here?

You’ve got a good start.

I think using some kind of physics object might be better suited to move characters than tweening. Possibly a BodyVelocity object put under the HumanoidRootPart.

Another thing I’d suggest is to flatten the camera’s look vector. I think that this will give you the desired dash results that you have in mind. Otherwise it is possible that players could dash up into the air, or dash downwards into the ground.

Edit: Here are some code samples to mess with.

local DASH_SPEED = 40
local DASH_TIME = 1

function flattenDirection(direction)
	if typeof(direction) == 'Vector3' then
		local flatDirection = (direction*Vector3.new(1,0,1)).unit
		if flatDirection.x == flatDirection.x then	-- If this is false, that means that the unitVector is NaN
			return flatDirection
		end
	end
	-- This is a fallback result incase flattening fails
	return Vector3.new(0,0,-1)
end

function dash(player, direction)
	if player and player.Parent then
		local character = player.Character
		if character and character.Parent == workspace then
			local hrp = character:FindFirstChild('HumanoidRootPart')
			local humanoid = character:FindFirstChildOfClass('Humanoid')
			if hrp and humanoid then

				if humanoid.Health <= 0 then
					-- Can't dash when you're dead. rip
					return
				end

				if hrp:FindFirstChild('DashBodyVelocity') then
					-- Player is already dashing
					return
				end

				local flatDirection = flattenDirection(direction)

				local bv = Instance.new('BodyVelocity')
				bv.Name = 'DashBodyVelocity'
				bv.MaxForce = Vector3.new(1,1,1) * 40000
				bv.Velocity = flatDirection * DASH_SPEED
				bv.Parent = hrp
				wait(DASH_TIME)
				if bv and bv.Parent then
					bv:Destroy()
				end
			end
		end
	end
end
2 Likes