Broken Velocity

REVISED: Any other gaming laptops is so good, that my velocity speed wouldn’t able to boost, this only happens in the Roblox Launcher, how do I fix this?

The LocalScript:

--[[ REFERENCES ]]--

-- local player --
local service = game:GetService("Players")
local player = service.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- player character parts --
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local module = require(script.Settings)
-- values --
local jumping = false
local airVelocity = Vector3.new()

--[[ FUNCTIONS ]]--

-- create a function to draw a line for indication --
local function drawLine(startPosition, endPosition)
	local line = Instance.new("LineHandleAdornment", game.Workspace.CurrentCamera)
	line.CFrame = CFrame.new(startPosition, endPosition)
	line.Adornee = game.Workspace.Terrain
	line.Length = (startPosition - endPosition).Magnitude
	line.Thickness = 2
	line.Color3 = Color3.new(1, 0, 0)
	game:GetService("Debris"):AddItem(line, 0)
end
-- projects the velocity onto the plane of the surface --
local function projectOntoPlane(velocity, normal)
	local dotProduct = velocity:Dot(normal)
	return velocity - dotProduct * normal
end
-- generate rays in a cone --
local function generateConeRays(origin, direction, spreadAngle, numberOfRays)
	local rays = {}
	local halfAngle = math.rad(spreadAngle / 2)
	for i = 0, numberOfRays - 1 do
		local angle = (i - (numberOfRays - 1) / 2) * (spreadAngle / (numberOfRays - 1))
		local rotation = CFrame.Angles(0, math.rad(angle), 0)
		table.insert(rays, Ray.new(origin, (rotation * direction).Unit * module.rayDistance))
	end
	return rays
end
-- multiplies rootPart's velocity speed --
game:GetService("RunService").Heartbeat:Connect(function()
	if rootPart and jumping then
		if airVelocity.Magnitude > 0 then
			local velocity = airVelocity * module.multiplier -- around 1.5
			local newVelocity = Vector3.new(velocity.X, rootPart.Velocity.Y, velocity.Z)
			local rayDirection = newVelocity.Unit * module.rayDistance -- around 1.5

			if newVelocity.Y < 0 then
				rayDirection = (newVelocity + Vector3.new(0, -newVelocity.Y, 0)).Unit * module.rayDistance
			else
				rayDirection = Vector3.new(rayDirection.X, 0, rayDirection.Z)
			end

			local rays = generateConeRays(rootPart.Position, rayDirection, 80, 5)
			local hitPart, hitPosition, hitNormal = nil

			for _, ray in ipairs(rays) do
				local part, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, {character})
				if part then
					hitPart, hitPosition, hitNormal = part, position, normal
					break
				end
			end

			if module.toggleLine then
				for _, ray in ipairs(rays) do
					drawLine(rootPart.Position, rootPart.Position + ray.Direction)
				end
			end

			if not hitPart then
				rootPart.Velocity = newVelocity
			elseif hitPart.CanCollide then
				local projectedVelocity = projectOntoPlane(newVelocity, hitNormal)
				airVelocity = projectedVelocity
				rootPart.Velocity = projectedVelocity
			end
		end
	else
		rootPart.Velocity = rootPart.Velocity * module.factor -- around 0.95
	end
end)
-- function from humanoid's state --
humanoid.StateChanged:Connect(function(_, newState)
	if newState == Enum.HumanoidStateType.Freefall then
		airVelocity = rootPart.Velocity
		jumping = true
	elseif newState == Enum.HumanoidStateType.Landed then
		jumping = false
	end
end)
1 Like