You can write your topic however you want, but you need to answer these questions:
-
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.
-
What is the issue? Further away from the origin of world, the more the player boosts forward
-
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.