Issue with physics?

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 Media

Code:

--!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()

If I had to guess, I’d say that the weight of the back of the ship is making the Roblox physics engine apply a rotational force.

However, using an AlignOrientation in conjunction with the VectorForce should do the trick. With the following settings:
AlignmentMode = OneAttachment
AlignType = PrimaryAxisParallel
PrimaryAxis = 0,1,0
As well as orienting the VectorForce’s attachment so that the PrimaryAxis (the yellow one) faces upward, you can create an AlignOrientation that doesn’t affect the Y-rotation. You can then connect the AlignOrientation to the same attachment as the VectorForce (since it shouldn’t be affected by the attachment’s rotation).
You may need to mess with the MaxTorque and Responsiveness attributes to get something that you like, but after that it should be smooth sailing.

sweet! got a scripter friend to help and practically said the same thing, floats perfectly!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.