How would I make a system where the player charges forward?

I am trying to make a system, where the player will constantly charge forward by holding a key bind(I already have the input part done), but gradually gets faster and faster. How would I go about doing this? This is the code I already have:

if PlayerIncoming == Player then
			print("Starting Dropkick")
			if UpdateConnection then
				UpdateConnection:Disconnect()
			end
			if VelocityObject then
				VelocityObject:Destroy()
			end
			if ForceTween and ForceTween.PlaybackState == Enum.PlaybackState.Playing then
				ForceTween:Cancel()
			end
			VelocityObject = Instance.new("BodyPosition")
			VelocityObject.Parent = Character.PrimaryPart
			local Params = RaycastParams.new()
			Params.FilterType = Enum.RaycastFilterType.Exclude
			Params.FilterDescendantsInstances = { Character }
			UpdateConnection = RunService.Heartbeat:Connect(function()
				print("Running")
				local PositionToGo
				local HumanoidRootPart = Character.PrimaryPart
				local RaycastResult = Workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0, 0, -20) * 5, Params)
				if RaycastResult then
					local FoundInstance = RaycastResult.Instance :: BasePart
					if FoundInstance.CanCollide == true then
						PositionToGo = RaycastResult.Position
					else
						PositionToGo = -(HumanoidRootPart.CFrame + (Vector3.new(0, 0, -20) * 10)).Position
					end
				else
					PositionToGo = -(HumanoidRootPart.CFrame + (Vector3.new(0, 0, -20) * 10)).Position
				end
				VelocityObject.Position = PositionToGo
			end)
			VelocityObject.MaxForce = Vector3.new(0, 0, 0)
			local PropertyTable = {
				["MaxForce"] = Vector3.new(50000, 50000, 50000),
			}
			ForceTween = TweenService:Create(VelocityObject, TINfo, PropertyTable)
			ForceTween:Play()
		end

This just does not work, so could anyone help?

1 Like

I think a fix here is to use HumanoidRootPart.CFrame+HumanoidRootPart.CFrame.LookVector*20 instead of all the Vector3(0, 0, -20) stuff.

Are you getting any errors and does the code do anything? I did a light skim of the script so I might’ve missed some details.

Edit: CFrame.LookVector to go in direction the HRP is facing rather than global direction, which is always gonna be the same

1 Like

it’s really slow, is there any way to increase velocity?

Try increasing the LookVectorNum to a higher number. Right now, it’s 20 (or -20, idk), try setting it to like 30 or 40. Ex. HumanoidRootPart.CFrameHumanoidRootPart.CFrame.LookVector*35
You can also change the P value of bodyposition too. Something around 2000 should be good.

1 Like

thanks! I will try to polish this, and I will tell you the results.

1 Like