How would I make it accelerate slower etc?

Hi,

I am trying to make a plane in my game.

It works, but I want to know how I would make it accelerate slower (slowing down and speeding up slower).

Because if I click W it takes half a second, and then it’s already up to max speed and it also happens when I click S.

I am using a BodyGyro to rotate the plane and a BodyVelocity to make it move.

local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local Engine = script.Obj.Value.Body.Engine
local camera = workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()
local flying = false
local speed = 0.5

local bv = Instance.new("BodyVelocity", Engine)
bv.MaxForce = Vector3.new()
bv.P = 99999999

local bg = Instance.new("BodyGyro", Engine)
bg.MaxTorque = Vector3.new()
bg.D = 350

local function Fly()
	flying = true

	while flying do
		
		bv.MaxForce = Vector3.new(40000000,40000000,40000000)
		bg.MaxTorque = Vector3.new(40000000,40000000,40000000)
		rs.RenderStepped:Wait()
		uis.MouseBehavior = Enum.MouseBehavior.LockCenter
		if uis:IsKeyDown(Enum.KeyCode.W) then
			bv.Velocity = Mouse.Hit.LookVector * 150
		elseif uis:IsKeyDown(Enum.KeyCode.S) and not uis:IsKeyDown(Enum.KeyCode.W) then
			bv.Velocity = Vector3.new(0,0,0)
			bv.MaxForce = Vector3.new(0,0,0)
			bg.MaxTorque = Vector3.new(bg.MaxTorque.X, 0, bg.MaxTorque.Z)
		elseif not uis:IsKeyDown(Enum.KeyCode.W) then
			bv.Velocity = Vector3.new(0,0,0)
			bv.MaxForce = Vector3.new(0,0,0)
			bg.MaxTorque = Vector3.new(bg.MaxTorque.X, 0, bg.MaxTorque.Z)
		end
		bg.CFrame = CFrame.new(camera.CFrame.Position, camera.CFrame.Position + camera.CFrame.LookVector * 20)
	end
end

local function endFlying()
	bg.MaxTorque = Vector3.new()
	bv.MaxForce = Vector3.new()
	uis.MouseBehavior = Enum.MouseBehavior.Default
	flying = false
end

uis.InputBegan:Connect(function(input)
	print("AVO")
	if input.KeyCode == Enum.KeyCode.E then
		if not flying then
			Fly()
		else
			endFlying()
		end
	end
end)

Change BodyVelocity.P, that might help. You should probably do this on the server, btw.

Edit: You could also use your own variables for speed, and customize it that way.

I tried changing the P to 1 and then to 999999 whatever.

It dosen’t change the acceleration for some reason.

Here’s a function I’ve got with custom physics (although this code was made for a car).

Engine.SetStatistics = function(player, car)
	_G.stats.players[player.Name] = {}
	local PlayerStats = _G.stats.players[player.Name]
	PlayerStats.car = car
	PlayerStats.max = {}
	PlayerStats.max.Speed = 50
	PlayerStats.max.Boost = 10
	PlayerStats.max.Slow = 10
	PlayerStats.max.Turn = 100
	PlayerStats.max.Gravity = 30
	PlayerStats.temp = {}
	PlayerStats.temp.Speed = 0
	PlayerStats.temp.Boost = 0
	PlayerStats.temp.Turn = 0
	PlayerStats.temp.Gravity = 0
	PlayerStats.temp.Angle = CFrame.new()
	PlayerStats.temp.Bounce = Vector3.new(0, 0, 0)
	PlayerStats.temp.Velocity = Vector3.new(0, 0, 0)
	PlayerStats.inc = {}
	PlayerStats.inc.Speed = 5
	PlayerStats.inc.Turn = 5
	PlayerStats.inc.Gravity = 1
	PlayerStats.keys = {}
	PlayerStats.keys['Up'] = false
	PlayerStats.keys['Down'] = false
	PlayerStats.keys['Left'] = false
	PlayerStats.keys['Right'] = false
	_G.stats.FindPlayerByCarValue = function(car)
		for _, player in pairs(game.Players:GetPlayers()) do
			if _G.stats.players[player.Name] and _G.stats.players[player.Name].car == car then
				return player
			end
		end
	end
end

It increases/decreases depending on the inc.Speed variable, but doesn’t go above max.Speed.

Engine.GetKeyEvent['Up'] = function(player)
	local PlayerStats = _G.stats.players[player.Name]
	local car = PlayerStats.car
	PlayerStats.keys['Up'] = true
	while PlayerStats.keys['Up'] == true do
		wait()
		if PlayerStats.temp.Speed < PlayerStats.max.Speed then
			PlayerStats.temp.Speed = PlayerStats.temp.Speed+PlayerStats.inc.Speed
		end
	end
end
2 Likes