Vehicle isnt moving forward?

So Im currently developing a Helicopter and so far its going O.K.
My only problem right now is that the Helicopter isnt moving forward correctly.
It can go up and down, turn and “should” be moving forward when I press forward but for some odd reason its only going forward in 4 Directions.

Here is a clip of my problem: (Please note that I am always pressing forward but it only goes forward when its 90 degree to the baseplate for some odd reason)
https://i.gyazo.com/cad1fda5e18126f41742dea6c38ed15f.mp4

Currently I am using BodyAngularVelocity to rotate it and BodyVelocity to make it go up and down and BodyThrust for the forward/backwards.
image

--Localscript
local ContextActionService = game:GetService("ContextActionService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local plane = script.Obj.Value

local RunService = game:GetService("RunService")
local height = 0
local turn = 0
local moving = 0

local vel = plane.Main.BodyVelocity
local tru = plane.Main.BodyThrust
local ang = plane.Main.BodyAngularVelocity

local speed = 100

function MoveUp(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		height = -5
	end
	if action_state == Enum.UserInputState.End then
		height = 0
	end
end

function MoveDown(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		height = 5
	end
	if action_state == Enum.UserInputState.End then
		height = 0
	end
end

function MoveLeft(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		turn = 1
	end
	if action_state == Enum.UserInputState.End then
		turn = 0
	end
end

function MoveRight(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		turn = -1
	end
	if action_state == Enum.UserInputState.End then
		turn = 0
	end
end

function MoveForward(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		moving = -50
	end
	if action_state == Enum.UserInputState.End then
		moving = 0
	end
end

function MoveBackwards(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		moving = 50
	end
	if action_state == Enum.UserInputState.End then
		moving = 0
	end
end

RunService:BindToRenderStep("Update", Enum.RenderPriority.Input.Value, function()

	tru.Force = Vector3.new(0,0,-moving) * 100
	ang.AngularVelocity = Vector3.new(0, turn, 0)
	vel.Velocity = Vector3.new(0,height,0)
end)

ContextActionService:BindAction("Up", MoveUp, false, "q")
ContextActionService:BindAction("Down", MoveDown, false, "e")
ContextActionService:BindAction("Left", MoveLeft, false, "a")
ContextActionService:BindAction("Right", MoveRight, false, "d")
ContextActionService:BindAction("Forward", MoveForward, false, "w")
ContextActionService:BindAction("Backwards", MoveBackwards, false, "s")
7 Likes

You can probably try this:

tru.Force = plane.Main.CFrame.lookVector * -moving * 100

Didnt work , still moves only in those 4 directions.
Would you check it out if I gave you the place files?

You have to constantly set the lookVector:

for me, I just use body velocity and body angular velocity

Part = -- The moving part
BV = Part.BodyVelocity
BAV = Part.BodyAngularVelocity

local function onChanged(property)

if property == "Steer" then

	if Seat.Steer == 1 then
		BAV.AngularVelocity = Vector3.new(0,-1,0)
	elseif Seat.Steer == -1 then
		BAV.AngularVelocity = Vector3.new(0,1,0)
	elseif Seat.Steer == 0 then
		BAV.AngularVelocity = Vector3.new(0,0,0)
	end
	
    if property == "Throttle" then
    		if Seat.Throttle == 1 then
    			while Seat.Throttle == 1 do
    				BV.Force = Vector3.new(Part.CFrame.LookVector.X * 700, 2000, script.Parent.Parent.Base.CFrame.LookVector.Z * 700) -- Change this to higher if it doesn't go up
    				wait()
    			end
    		elseif Seat.Throttle == 0 then
    			BV.Force = Part.CFrame.LookVector * 0
    		end
    	end

But i am constantly setting the LookVector.
Here, its in a loop:

RunService:BindToRenderStep("Update", Enum.RenderPriority.Input.Value, function()

	tru.Force = plane.Main.CFrame.lookVector * moving * 100
	ang.AngularVelocity = Vector3.new(0, turn, 0)
	vel.Velocity = Vector3.new(0,height,0)
end)

Isnt it constantly checking?

Edit: accidentally edited this post

I posted this on top already but here u go
image

Its in a normal script which is then given the player who sits on the driverSeat to get Netwrokownership.

2 Likes

i am unable to recreate( your set-up) what you have in your video, do you have a place file that i can view and do some testing in?

Yes! Please, any help is appreciated.

Basicly I want it to go up/down and forward/backwards and ofc turn.
forDEV.rbxl (23.4 KB)

1 Like

I’m on mobile right now, but I’ll look into it as soon as I can!

Thank you… I’ve been trying to make it work for 2 days now. I actually got it kinda working with moving the part up/down with bodythrusters and moving it forward/backwards with bodyvelocity.
That did the trick BUT It only works on a part or something small. When I tried using a helicopter model for example it didnt work that good. The up/down from the bodythruster didnt work very well, so I think bodythrusters aren’t the way to go.

try your best m8! I appreciate it!

Have you tried subtracting the position of main from the look vector?

tru.Force = (plane.Main.Position - plane.Main.CFrame.lookVector*999).unit * moving * 100

Sorry for the late reply, so after doing some testing using various different body movers, i felt as though using body gyro and Body Force did quite well in replicating movements of a helicopter( some-what), here is the the result:

(i also made it so when you tilt forward or backward the part/ helicopter moves in that direction and i changed the right and left movement functions a little)

You will probably have to play around with the body movers and lower some densities of parts to work with heaver objects(helicopter)

Here's the edited Code
--Localscript
local ContextActionService = game:GetService("ContextActionService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local plane = script.Obj.Value

local RunService = game:GetService("RunService")
local height = 0
local turn = 0
local moving = 0
local Tilt = 0


local MoveRightKeyDown = false
local MovetLeftKeyDown =false

local vel = plane.Main.BodyVelocity
local tru = plane.Main.BodyForce
local BodyGyro = plane.Main.BodyGyro

local speed = 20

function MoveUp(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		height = 50
	end
	if action_state == Enum.UserInputState.End then
		height = 0
	end
end

function MoveDown(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		height = -50
	end
	if action_state == Enum.UserInputState.End then
		height = 0
	end
end

function MoveLeft(action_name, action_state)
	MovetLeftKeyDown = false
	if action_state == Enum.UserInputState.Begin then
MovetLeftKeyDown = true
	while MovetLeftKeyDown do
		wait(0.1)
		turn = turn + 5
	end
	 elseif action_state == Enum.UserInputState.End then
      MovetLeftKeyDown = false
end

end



function MoveRight(action_name, action_state)
	MoveRightKeyDown = false
	if action_state == Enum.UserInputState.Begin then
MoveRightKeyDown = true
	while MoveRightKeyDown do
		wait(0.1)
		turn = turn - 5
end
	 elseif action_state == Enum.UserInputState.End then
      MoveRightKeyDown = false
end

end

function MoveForward(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		moving = -5000
		 Tilt = -10
	end
	if action_state == Enum.UserInputState.End then
		moving = 0
		 Tilt = 0
	end
end

function MoveBackwards(action_name, action_state)
	if action_state == Enum.UserInputState.Begin then
		moving = 5000
		 Tilt = 10
	end
	if action_state == Enum.UserInputState.End then
		moving = 0
		Tilt = 0
	end
end



RunService:BindToRenderStep("Update", Enum.RenderPriority.Input.Value, function()
	
	BodyGyro.CFrame = CFrame.Angles(0, math.rad(turn), 0) * CFrame.Angles(math.rad(Tilt), 0, 0)
	tru.Force = plane.Main.CFrame.LookVector * (-moving * 2 )
	vel.Velocity = Vector3.new(0,height,0)
	
end)

ContextActionService:BindAction("Down", MoveDown, false, "q")
ContextActionService:BindAction("Up", MoveUp, false, "e")
ContextActionService:BindAction("Left", MoveLeft, false, "a")
ContextActionService:BindAction("Right", MoveRight, false, "d")
ContextActionService:BindAction("Forward", MoveForward, false, "w")
ContextActionService:BindAction("Backwards", MoveBackwards, false, "s")

TestPlace.rbxl (23.2 KB)

if you have any question i would be glad to try and answer, have a good day or night!

21 Likes

Wow, it works like a charm. For Test reasons I build a little “more looking like” helicopter to see if it works with larger scale and it does!

My only “problem” is the speed. Right now it only goes forward when I have 4000 Force and I am flying with a speed of over 250.
Is there a way to better control the speed limit?

Thanks so much!

3 Likes

Also is there a way to get some kind of acceleration with BodyForce?
I searched around the web and only see Bodyvelocity with acceleration.

1 Like

You can simply scale up to the desired maximum force over time (use a for loop to interpolate from 0 to the desired force).

2 Likes

First of all my problem is speed, how do I limit it.

And second when I jump off the Vehicle Seat I cannot move and the Vehicle still moves.

1 Like

You have to unbind the current keybinds to unlock character movement.

If you make a helicopter (with all of the things in a helicopter) you might want to go to CustomPhysicalProperties and turn the density property to 0.

Plus, for one part you might want to make the density a little higher than 0. Try 0.6 or something like that.

2 Likes