Hello everyone! So I was trying to make a hot air balloon system using Linear Velocities and I am having trouble putting it together. Basically I just modify the VectorVelocity whenever they do certain inputs and heres the code I used to do that:
MoveBallon.OnServerEvent:Connect(function(plr, input)
if input == Enum.KeyCode.E then
BalloonModule.MoveUp(HotAirBalloon)
end
if input == Enum.KeyCode.Q then
BalloonModule.MoveDown(HotAirBalloon)
end
if input == Enum.KeyCode.W then
BalloonModule.MoveFoward(HotAirBalloon)
end
if input == Enum.KeyCode.S then
BalloonModule.MoveBackward(HotAirBalloon)
end
end)
The code for the actual module is here:
local module = {}
function removeValues(attach)
for _, v in attach:GetChildren() do
if v.Name == "LinearVelocity" then
v:Destroy()
end
end
end
function module.MoveUp(balloon)
local at0 = balloon.Primary.Attachment
if at0:FindFirstChild("UP") then
at0:FindFirstChild("UP"):Destroy()
end
local firstVel = Instance.new("LinearVelocity")
firstVel.Attachment0 = at0
firstVel.ForceLimitMode = Enum.ForceLimitMode.Magnitude
firstVel.MaxForce = math.huge
firstVel.RelativeTo = "World"
firstVel.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
firstVel.VectorVelocity = Vector3.new(0, 15, 0)
firstVel.Name = "UP"
firstVel.Parent = at0
end
function module.MoveDown(balloon)
if balloon.Primary.CFrame.Position.Y <= 16.5 then
print("ON GROUND TOO LOW")
return
end
local at0 = balloon.Primary.Attachment
local lv: LinearVelocity = at0:FindFirstChildWhichIsA("LinearVelocity")
lv.VectorVelocity = Vector3.new(lv.VectorVelocity.X, -15, lv.VectorVelocity.Z)
end
function module.MoveFoward(balloon)
if balloon.Primary.CFrame.Position.Y <= 16.5 then
print("ON GROUND TOO LOW")
return
end
local at0 = balloon.Primary.Attachment
removeValues(at0)
local vel: LinearVelocity = at0:FindFirstChildWhichIsA("LinearVelocity")
vel.VectorVelocity = Vector3.new(vel.VectorVelocity.X, vel.VectorVelocity.Y, -15)
end
function module.MoveBackward(balloon)
if balloon.Primary.CFrame.Position.Y <= 16.5 then
print("ON GROUND TOO LOW")
return
end
local at0 = balloon.Primary.Attachment
removeValues(at0)
local vel: LinearVelocity = at0:FindFirstChildWhichIsA("LinearVelocity")
vel.VectorVelocity = Vector3.new(vel.VectorVelocity.X, vel.VectorVelocity.Y, 15)
end
return module
Whenever I do the inputs for foward and backward the balloon model starts to act weird and tilts all over the place. To combat tbis I tried using align orientation so it would sit still but that still didn’t fix my issue. I don’t know if this would be much help but here is my Align Orientation settings:
If anyone has any questions or answers please I need help and it would be appreciated!!