How to propel player towards look direction?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want the player to boost up and towards the look direction of the root part when he/she presses shift.

  2. What is the issue? Further away from the origin of world, the more the player boosts forward

  3. What solutions have you tried so far? I can’t really think of alternatives

Essentially, can someone provide me help as to a better way to propel the player forward in his look direction? Right now, it isn’t very reliable as it boosts the player further each time the player gets farther from origin, due to it adding the players bigger x/z lookdirection coordinates to the current coordinates, making the player jump further.

local ContextActionService = game:GetService('ContextActionService')
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local root = char:WaitForChild('HumanoidRootPart')
local jetEnabled = false

function toggleJet()
	print('Toggled: ', jetEnabled)
	if not jetEnabled then
		local BodyVelocity = Instance.new('BodyVelocity')
		local forwardX, forwardZ = root.CFrame.X, root.CFrame.Z --main issue here
		print(forwardX)
		BodyVelocity.MaxForce = Vector3.new(5000, 5000, 5000)
		BodyVelocity.Velocity = Vector3.new(0, 50, 0)  + Vector3.new(forwardX*10, 0, forwardZ*10) --main issue here
		BodyVelocity.P = 10
		BodyVelocity.Parent = root
		jetEnabled = not jetEnabled
	else
		jetEnabled = not jetEnabled
		root:FindFirstChild('BodyVelocity'):Destroy()
	end
end

ContextActionService:BindAction('ToggleJet', toggleJet, false, Enum.KeyCode.LeftShift)

So yeah. If you could help me out and point me in the right direction, I’d appreciate it. Thanks a ton.

There are a few problems here. First, you want look direction, and CFrame.X, CFrame.Z isn’t suitable for this. There are two different versions of “look direction” we can use!

There is Camera.CFrame.LookVector which finds the looking direction of the player’s camera, and there is root.CFrame.LookVector (this is probably what you want) which is the looking direction of the player’s character.

Both of these return a normal vector3, meaning they always have a distance of 1! This also means they don’t change as you go further away from the origin.

4 Likes

Ok thank you! I forgot LookVector was a normal vector.