Problems with bodyvelocity

Hello everyone, im trying to make a plane with bodyvelocity but for some reson it doesn’t move.

Script:

local part = script.Parent.Parent.Main
local event = script.Parent.Plane
local bv = part.BodyVelocity

event.OnServerEvent:Connect(function(plr, running)
	if running == true then
		print("Moving")
		bv.Velocity = part.CFrame.LookVector * 150
	elseif running == false then
		print("Not moving")
		bv.Velocity = part.CFrame.LookVector * 1
	end
end)

Everything prints correctly.

Are there any parts in the plane model that are anchored? If so, every force applied to the parts welded to the plane model will remain rigid.

2 Likes

There are no anchored parts, for soem reason before when I was trying to do it by changing the part’s velocity the part moved, but I switched to bodyvelocity because according to the wiki it can give a constant speed. And now it doesnt move.

1 Like

There are two possibilities, Firstly as @C_Sharper has mentioned your parts may be anchored,

Secondly, you may not have enough “MaxForce” or “P” on your BodyVelocity, try changing your maxforce to Vector3.new(math.huge,math.huge,math.huge)

3 Likes

Still not working:

local part = script.Parent.Parent.Main
local event = script.Parent.Plane
local bv = part.BodyVelocity

event.OnServerEvent:Connect(function(plr, running)
	if running == true then
		print("Moving")
		bv.Velocity = part.CFrame.LookVector * 150
		bv.P = Vector3.new(math.huge,math.huge,math.huge)
	elseif running == false then
		print("Not moving")
		bv.Velocity = part.CFrame.LookVector * 1
		bv.P = Vector3.new(math.huge,math.huge,math.huge)
	end
end)
1 Like

Change P to MaxForce
(30 chars)

1 Like

Works well now, only one issue, when I stop it, it stays levitating in the air, how do I do it so it falls down to the ground?

Script:

local part = script.Parent.Parent.Main
local event = script.Parent.Plane
local bv = part.BodyVelocity

event.OnServerEvent:Connect(function(plr, running)
	if running == true then
		print("Moving")
		bv.Velocity = part.CFrame.LookVector * 150
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	elseif running == false then
		print("Not moving")
		bv.Velocity = part.CFrame.LookVector * 0
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	end
end)

bv.Velocity = 0,

30chars30chars30chars30chars

2 Likes

If I do that it says I need vector3.
Tried this but it still stays levitating.

local part = script.Parent.Parent.Main
local event = script.Parent.Plane
local bv = part.BodyVelocity

event.OnServerEvent:Connect(function(plr, running)
	if running == true then
		print("Moving")
		bv.Velocity = part.CFrame.LookVector * 150
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	elseif running == false then
		print("Not moving")
		bv.Velocity = Vector3.new(0,0,0)
		bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	end
end)

Try just deleting the body-velocity from the plane

1 Like

So these two scripts make the plane move, the first one makes it go straight and the second one lets it steer.

local part = script.Parent.Parent.Main
local event = script.Parent.Plane

event.OnServerEvent:Connect(function(plr, running)
	if running == true then
		print("Moving")
		local i = Instance.new("BodyVelocity")
		local c = Instance.new("BodyAngularVelocity")
		c.Parent = part
		i.Parent = part
		i.Velocity = part.CFrame.LookVector * 150
		i.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	elseif running == false then
		print("Not moving")
		part.BodyVelocity:Destroy()
		part.BodyAngularVelocity:Destroy()
	end
end)
local seat = script.Parent

SteerSpeed = 850

seat.Changed:Connect(function(p)
	if p == "SteerFloat"then
			local s = script.Parent.Parent.Main.BodyAngularVelocity
		s.AngularVelocity = Vector3.new(0,-SteerSpeed*seat.SteerFloat,0)
	end
end)

Now, for some reason when steering the plane rotates, but doesnt advance in the direction you steer.
https://gyazo.com/5cd176ad2f3d63e1c69190de2ab625f7

You need to update the velocity, it’s pointing in the old direction, You need to update the body velocity when you update the bodyangular velocity.

Also, i notice your plane’s a bit un-animated, If you want to add acceleration and de-acceleration you can change the bodyVelocity using a for loop.

for i = 0, 150 do
BV.Velocity = part.CFrame.LookVector * i
end
1 Like

I first wanna get the main part done.
I have been trying ddifferent ways of updating the CFrame but all of them dont work or are bugged. How could I do it?

This is the current script im using:

local part = script.Parent.Parent.Main
local event = script.Parent.Plane

event.OnServerEvent:Connect(function(plr, running)
	if running == true then
		print("Moving")
		local i = Instance.new("BodyVelocity")
		local c = Instance.new("BodyAngularVelocity")
		c.Parent = part
		i.Parent = part
		i.Velocity = part.CFrame.LookVector * 150
		i.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	elseif running == false then
		print("Not moving")
		part.BodyVelocity:Destroy()
		part.BodyAngularVelocity:Destroy()
	end
end)

Edit:

Just tried this but it doesnt work:

local part = script.Parent.Parent.Main
local event = script.Parent.Plane

event.OnServerEvent:Connect(function(plr, running)
	wait(0.2)
	part.BodyVelocity:GetPropertyChangedSignal("Velocity"):Connect(function()
		part.BodyVelocity.Velocity = part.CFrame.LookVector * 150
	end)
end)
local part = script.Parent.Parent.Main
local event = script.Parent.Plane

event.OnServerEvent:Connect(function(plr, running)
	if running == true then
		print("Moving")
		local i = Instance.new("BodyVelocity")
		local c = Instance.new("BodyAngularVelocity")
		c.Parent = part
		i.Parent = part
		i.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	elseif running == false then
		print("Not moving")
		part.BodyVelocity:Destroy()
		part.BodyAngularVelocity:Destroy()
	end
end)
local seat = script.Parent

SteerSpeed = 850

seat.Changed:Connect(function(p)
	if p == "SteerFloat"then
			local s = script.Parent.Parent.Main.BodyAngularVelocity
            local bv = script.Parent.Parent.Main.BodyVelocity 
		    s.AngularVelocity = Vector3.new(0,-SteerSpeed*seat.SteerFloat,0)
            bv.Velocity = script.Parent.Parent.Main.CFrame.LookVector * 150
	end
end)

This is what i meant when changing updating the velocity with the angularvelocity

1 Like

For some reason it updates only sometimes
https://gyazo.com/6b2de002fa77f9e9b41d9dda888ac554

This is because the angular velocity is only changed once and same with the body velocity, you’ll have to constantly change the body velocity, put it on a loop inside of the seat.changed function

1 Like

Ok, so stuff works fine, the plane can go up and down, right and left but there is one problem, when you want to go up and right at the same time, only one of them works, since im modifying the same bodyangularvelocity. I have tried using 2 angularvelocities in the same part, but for some reason it doesn’t work, is there any solution to this?

Yes, how are you handling the controls? is it a remotevent + userinputservice or solely a vehichle seat.

Both can be used, Check if the throttle is changed, if minus, go down, plus go up,

Put it all on a loop which fires when a pilot is in the plane, one sec i will supply an example

1 Like

Im using userimputservice to detect when the player presses e and turn on the plane with a remote event. And using a vehicle seat to maneuver it.

Also when I go up or down, when im facing some ways, it works well, but other times, it rotates differently.(https://gyazo.com/143844e660260c84a76a76ef4fd8dc98)

And another issue is that while im turning, the more time i hold the key to turn, the faster the plane turns until I release the key.

So here’s how i would do it.

local BreakLoop

function StartLoop()
while wait() do
if BreakLoop then break end
if Throttle then
local PitchAngularVelocity
--PitchAngularVelocity = seat.throttle divided or multiplied by a value (to make the plane
--pitch up / down slower / faster)
end

if Steer then
local SteerAngularVelocity 
--SteerAngularVelocity = Seat.Steer divided or multiplied by a value (to make the
--plane rotate left/right faster/slower)
end
end
end

game.ReplicatedStorage.PlaneStarted:Connect(function(plr)
if Seat.Occupant = plr.Character then
BreakLoop = false
StartLoop()
end
end

You basically start a loop which updates both angular velocities as they’re both checked.
Then, from that you define Both AngularVelocities and you change them according to a formula like such:
SteerAngularVelocity = seat.Steer / 5 (This will make the SteerAngularVelocity slower than the steer of the seat)

You will also want to add a check to see if the player has left the plane, in which case, break the loop and let the plane’s velocity die out by updating it with a for loop.

EDIT: I just checked the video you sent, That’s probably due to the wrong AngularVelocity math, it seems like it’s pitching on x when it should be pitching on z.

1 Like