LookVector Not working properly

I’m trying to create a boost/NOS system using BodyVelocity, but the problem is that it doesn’t work in all directions, particularly where the player is driving. It only propels the vehicle forward, and when I turn or drive in the backward direction, it slows down. Additionally, it doesn’t function properly when turning right or left.

local isBoosting = false
local model = script.BodyValue.Value

local exhaust = model.Body:WaitForChild("Boost").Trail0
local boostTorque = 50


local bodyVelocity = Instance.new("BodyVelocity", script.Parent)
bodyVelocity.MaxForce = Vector3.new(0,0,0)
bodyVelocity.Velocity = Vector3.new(0,0,0)

function Boost()
	if not isBoosting and script.Parent.Occupant then
		isBoosting = true

		local player = script.Parent.Occupant.Parent
		local boostDirection = player.HumanoidRootPart.CFrame.LookVector

		bodyVelocity.MaxForce = boostDirection * boostTorque
		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = true
			end
		end

		wait(4)

		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = false
			end
		end
		bodyVelocity.MaxForce = Vector3.new(0, 0, 0)

		isBoosting = false
	end
end

game.ReplicatedStorage:WaitForChild("Boost").OnServerEvent:Connect(Boost)
1 Like

Because you need to update the lookvector on a loop, such as

while bodyVelocity ~= nil do
    if player:FindFirstChild("HumanoidRootPart") ~= nil then
        boostDirection = player.HumanoidRootPart.CFrame.LookVector
        bodyVelocity.Velocity = boostDirection
    end
    task.wait()
end
2 Likes

I replaced this line bodyVelocity.MaxForce = boostDirection * boostTorque with the line you provided and the it doesnt really move or boost the vehicle…

bodyVelocity.Velocity = boostDirection

There might be no need for it to update cause as I mentioned earlier if I start driving on some other directions other than the “Front”-- basing it using the “View Selector”

1 Like

Try this.

local isBoosting = false
local model = script.BodyValue.Value

local exhaust = model.Body:WaitForChild("Boost").Trail0
local boostTorque = 50


local bodyVelocity = Instance.new("BodyVelocity", script.Parent)
bodyVelocity.MaxForce = Vector3.new(0,0,0)
bodyVelocity.Velocity = Vector3.new(0,0,0)

function Boost()
	if not isBoosting and script.Parent.Occupant then
		isBoosting = true

		local player = script.Parent.Occupant.Parent
		local boostDirection = player.HumanoidRootPart.CFrame.LookVector

		bodyVelocity.MaxForce = boostDirection * boostTorque
		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = true
			end
		end

                coroutine.wrap(function()
                   while isBoosting == true do
    if player:FindFirstChild("HumanoidRootPart") ~= nil then
        boostDirection = player.HumanoidRootPart.CFrame.LookVector
        bodyVelocity.Velocity = boostDirection
    end
    task.wait()
end
                end)()

		wait(4)

		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = false
			end
		end
		bodyVelocity.MaxForce = Vector3.new(0, 0, 0)

		isBoosting = false
	end
end

game.ReplicatedStorage:WaitForChild("Boost").OnServerEvent:Connect(Boost)
1 Like

Update, I used the script you provided and somehow it now works on the Right Direction but on the Left Direction it just slows down and for the Front it still work but for the back It does the same thing it slows down.

1 Like

Does the root part move or only the torso?

2 Likes

ummm this is what it looks like
image

Is there like a possible way to like multiply a value when the player is looking on the opposite way so that the value will work?

It should work no matter where the player looks, mabye try replacing the code inside the loop with this

if player:FindFirstChild("UpperTorso") ~= nil then
        boostDirection = player.UpperTorso.CFrame.LookVector
        bodyVelocity.Velocity = Vector3.new(boostDirection.X, 0, boostDirection.Z)
end
1 Like

It still does the same like the Picture I sent before:
image

local isBoosting = false
local model = script.BodyValue.Value

local exhaust = model.Body:WaitForChild("Boost").Trail0
local boostTorque = 50


local bodyVelocity = Instance.new("BodyVelocity", script.Parent)
bodyVelocity.MaxForce = Vector3.new(0,0,0)
bodyVelocity.Velocity = Vector3.new(0,0,0)

function Boost()
	if not isBoosting and script.Parent.Occupant then
		isBoosting = true

		local player = script.Parent.Occupant.Parent
		local boostDirection = player.HumanoidRootPart.CFrame.LookVector

		bodyVelocity.MaxForce = boostDirection * boostTorque
		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = true
			end
		end

		coroutine.wrap(function()
			while isBoosting == true do
				if player:FindFirstChild("UpperTorso") ~= nil then
					boostDirection = player.UpperTorso.CFrame.LookVector
					bodyVelocity.Velocity = Vector3.new(boostDirection.X, 0, boostDirection.Z)
				end
				task.wait()
			end
		end)()

		wait(4)

		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = false
			end
		end
		bodyVelocity.MaxForce = Vector3.new(0, 0, 0)

		isBoosting = false
	end
end

game.ReplicatedStorage:WaitForChild("Boost").OnServerEvent:Connect(Boost)

Let me open up studio and make my own code for this, then I’ll get back to you :wink:

1 Like

Alright, I’ll wait, and thanks for helping me :smiley:

This is how its most likely its doing, it boost in the right and backward direction but on the opposite directions it doesnt.

Woopsie I just found the problem

local isBoosting = false
local model = script.BodyValue.Value

local exhaust = model.Body:WaitForChild("Boost").Trail0
local boostTorque = 50


local bodyVelocity = Instance.new("BodyVelocity", script.Parent)
bodyVelocity.MaxForce = Vector3.new(0,0,0)
bodyVelocity.Velocity = Vector3.new(0,0,0)

function Boost()
	if not isBoosting and script.Parent.Occupant then
		isBoosting = true

		local player = script.Parent.Occupant.Parent
		local boostDirection = player.HumanoidRootPart.CFrame.LookVector

		bodyVelocity.MaxForce = boostDirection * boostTorque
		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = true
			end
		end

		coroutine.wrap(function()
			while isBoosting == true do
				if player:FindFirstChild("HumanoidRootPart") ~= nil then
					boostDirection = player.HumanoidRootPart.CFrame.LookVector
                   bodyVelocity.MaxForce = boostDirection * boostTorque
					bodyVelocity.Velocity = boostDirection
				end
				task.wait()
			end
		end)()

		wait(4)

		for _, v in pairs(exhaust:GetChildren()) do
			if v:IsA("Trail") then
				v.Enabled = false
			end
		end
		bodyVelocity.MaxForce = Vector3.new(0, 0, 0)

		isBoosting = false
	end
end

game.ReplicatedStorage:WaitForChild("Boost").OnServerEvent:Connect(Boost)

Sorry I forgot to also update the max force :grimacing:
It should work now :wink:

1 Like

Sorry but it still does the same…

Ok then let me make the updated code

1 Like

Alright… again, thanks for helping

local isBoosting = false
local model = script:WaitForChild('BodyValue').Value

local exhaust = model:WaitForChild("Body"):WaitForChild('Trail0')
local boostTorque = 50

local bodyVelocity = Instance.new("BodyVelocity", script.Parent)
bodyVelocity.MaxForce = Vector3.new()
bodyVelocity.Velocity = Vector3.new()

game:GetService("ReplicatedStorage"):WaitForChild("Boost").OnServerEvent:Connect(function(plr)
	if isBoosting == false and script.Parent.Occupant ~= nil then
		local player = script.Parent.Occupant.Parent
		
		if player ~= nil then
			if game:GetService("Players"):GetPlayerFromCharacter(player) == plr then
				
				local human = player:FindFirstChildWhichIsA("Humanoid")
				local root = human.RootPart
				
				if root ~= nil then

					bodyVelocity.MaxForce = root.CFrame.LookVector * boostTorque
					bodyVelocity.Velocity = root.CFrame.LookVector
					
					isBoosting = true
					
					for _, v in pairs(exhaust:GetChildren()) do
						if v:IsA("Trail") then
							v.Enabled = true
						end
					end
					
					coroutine.wrap(function()
						while isBoosting == true do -- Ignore this error, it's fine
							bodyVelocity.MaxForce = root.CFrame.LookVector * boostTorque
							bodyVelocity.Velocity = root.CFrame.LookVector
							task.wait()
						end
					end)()
					
					task.wait(4)
					
					isBoosting = false
					
					for _, v in pairs(exhaust:GetChildren()) do
						if v:IsA("Trail") then
							v.Enabled = false
						end
					end
					bodyVelocity.MaxForce = Vector3.new(0, 0, 0)
				end
			end
		end
	end
end)```

Give this a try
1 Like

It still does the same but I was playing around with the values on the Velocity if its value is positive and the value of the MaxForce is also Positive then both of the directions works fine. currently it is impossible for the values to be turned “Positive” sorry for my bad english.

Well I’m glad your problem has been solved! Can’t wait to see what the finished product looks like!