Hi all, I am trying to compose a function that keeps a part suspended at a constant height from a hit position, using bodythrusts. The below is what I have thus far, but I know that my logic behind applying the force is incorrect, as it thrusts up past the given height, and falls down. I would appreciate if anyone can at least help me solve this dilemma. Thanks!
local thrust = {} local RunService = game:GetService("RunService") local function getmass(part) return part:GetMass()*workspace.Gravity end function thrust:hover(thruster, height, a) local mass = getmass(thruster) local force = mass * a local obj = thruster:FindFirstChild("thrust") --//BodyThrust RunService.RenderStepped:connect(function() local r = Ray.new(thruster.Position, thruster.CFrame.upVector * -30) local ignore = {thruster} local part, pos, face = workspace:FindPartOnRayWithIgnoreList(r, ignore, false, true) local distance =(thruster.Position - pos).magnitude obj.Force = Vector3.new(0, (height/distance)*force, 0) end) end return thrust
Script calling hover:
require(game.ReplicatedStorage.ModuleScript):hover(script.Parent, 3, 2)