I’m trying to write a jetpack system where you change direction and speed using Left and right mouse buttons.
I’m having some problems with changing the direction & the speed.
Could anyone explain how to change vector force direction to the direction the player is looking.
Thanks.
1 Like
local direction = character.PrimaryPart.CFrame.LookVector
local force = direction * 1000
or if you want to get the players up vector
local direction = character.PrimaryPart.CFrame.UpVector
local force = direction * 1000
or if you want to use the cameras direction
local direction = game.Workspace.CurrentCamera.CFrame.LookVector
local force = direction * 1000
this video might also help you
I’ve written the following script
local VF = Instance.new("VectorForce")
local speed = 100
print(speed)
VF.Parent = script.Parent:WaitForChild("HumanoidRootPart")
VF.Attachment0 = VF.Parent:WaitForChild("RootRigAttachment")
game:GetService("RunService").RenderStepped:Connect(function()
if game:GetService("UserInputService"):IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
if speed < 200 then
print(speed)
speed = speed * 1.01
VF.Force = game.Workspace.CurrentCamera.CFrame.LookVector * speed
else
speed = 200
end
VF.Force = game.Workspace.CurrentCamera.CFrame.LookVector * speed
elseif game:GetService("UserInputService"):IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then
if speed > 100 then
print(speed)
speed = speed / 1.01
else
speed = 100
end
VF.Force = game.Workspace.CurrentCamera.CFrame.LookVector * speed
end
end)
Unfortunately the script is broken. The character only moves up and down.
Your force is kinder low
Plus you will be fighting gravity
Also your setting the force in left click twice for no reason once is enough
Also I do not recommend tweening the speed like that but use the vector force properties to adjust how quickly the player accelerates
Maybe you will have more success with LinearVelocity