Hi! Issue with a physics thing I’m trying to do, uncertain if I’m doing it correctly, however my model likes to dip down for no reason when I try to apply a counteractive force against gravity and goes down butt end, any suggestions? Trying to make an airship, thanks!
External MediaCode:
--!strict
local ships = game.Workspace:WaitForChild("Ships")
local grav = workspace.Gravity
local SHIP_HULL_NAME: "Bottom" = "Bottom"
function initShip(ship: Model) -- intialize the ships necessary forces and template objects
if ship.Name == "Dinghy" and ship:IsA("Model") then
assert(ship.PrimaryPart ~= nil, "Ship must have a PrimaryPart set") -- hi stupid
local primarypart = ship.PrimaryPart
-- assert that objects exist and forces are there
local shipHull: BasePart = ship:FindFirstChild(SHIP_HULL_NAME) :: BasePart
assert(shipHull ~= nil, "Ship must have a hull!")
local vectorForce: VectorForce = shipHull:FindFirstChild("VectorForce") :: VectorForce
assert(vectorForce ~= nil, "Ship must have a VectorForce!")
local anti_grav = primarypart.AssemblyMass * grav -- multiply mass * gravity to achieve effect
vectorForce.Force = Vector3.new(0, anti_grav, 0) -- apply the force
end
end
function initAllShips() -- grab all ships within the folder and apply the same anti grav effect
for _ , ship in pairs(ships:GetChildren()) do
initShip(ship)
end
end
ships.ChildAdded:Connect(initShip) -- if child gets added apply the initships
initAllShips()