Dash distance changes when in air

the script below dashes the player to the front when he double taps W. the set distance/speed is set to 330. though i have noticed that when i dash in the air the distance drastically multiplies. how is it possible to make the distance the same for every occasion? can anyone help

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local Tapped = false
local cd = false

UserInputService.InputBegan:Connect(function(Input, GameStuff)
	if cd == false then
		
		if GameStuff then return end
		if Input.KeyCode == Enum.KeyCode.W then
			if not Tapped then
				Tapped = true
				wait(0.2)
				Tapped = false
			else
				Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*330 
				cd=true
				local Animation = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(script.Animation)
				Animation:Play()
				
				wait(2.5)
				cd = false
			end
		end
	end
end)

roblox physics; I believe this is because when the character is dashing on the floor, more forces are taking over it, making the character move a shorter distance, and since when the character is in the air, there are less forces taking over it, thus making the character move further.


I suggest using BodyVelocity to dash the player forwards, and set the MaxForce to something really huge like 25000 (so forces cannot take over and the character can dash the same distance despite being on the ground or on the sky).

1 Like

alright, i think i understand what u mean but i dont understand how to script it. im a bad scripter, could you help?

Following up with what phxtn said, if you don’t fully understand BodyVelocity or any other body forces I suggest you watch several videos on them and read their API doc.

This is a pretty decent video: https://www.youtube.com/watch?v=pdUZsr8ccdU

what im trying to say is, i cant script yet. im trying to learn it but currently all i can do is make some variables and make a function

Yeah sure:

adding a BodyVelocity cannot be done on the client, so you’d have to fire a RemoteEvent from the localscript, which the serverscript will pick up.

In the serverscript you would add the body velocity and parent it to the players HumanoidRootPart, and set two values: Velocity, MaxForce. You wouldn’t want the player dashing forever so you would remove the bodyvelocity after around .5 seconds (Because the body velocity will always be enabled as long as it exists.)

Here is a coded example:

Local script:

--Bla bla bla you know what to do
--Player presses something if cooldown == false then
remoteEvent:FireServer() 

Server script:

RemoteEvent.OnServerEvent:Connect(function(player) 
	local bodyVel = Instance.new("BodyVelocity",player.Character.HumanoidRootPart) -- Creating the bodyevelocity
	bodyVel.MaxForce = Vector3.new(25000,25000,25000) -- setting its maxforce so that other forces cannot take over it
	bodyVel.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector*50 -- Determining the speed.
	wait(0.4)
	bodyVel:Destroy() -- Destroying the bodyvelocity because we do not want it anymore
end)

Also:

I’d recommend learning the basics and stuff instead of jumping into harder things, before knowing the basics.

1 Like

im wondering if i can paste the second script into the script because idk where and what to put in the new server script

In the new serverscript, you just pick up the remotevent signal and add the bodyvelocity into the player