I made my own orbit physics even months ago, This is based from a non-roblox related minigame I made with another person some time ago, where you could launch debris rocks and orbit them around the sun. Now, I decided to make it an actual thing and you can finally create your own objects with orbit physics.
You can also try the test place here, It’s uncopylocked so you may take the module there too.
API Reference:
-- Constructors:
Orbit.new(Position:Vector3, Speed:Vector3):Physics -- Creates a new orbit physics object.
-- Properties:
Physics.Position:Vector3 -- The position of the object.
Physics.Speed:Vector3 -- The speed or velocity of the object.
-- Functions (Physics)
Physics:Attract(Target:Vector3,Influence:number):Physics -- Modifies the speed to attract the object to a location.
Physics:Repel(Target:Vector3,Influence:number):Physics -- Modifies the speed to repel the object from a location.
Physics:Slow(Influence:number):Physics -- Slows down the velocity of the object.
-- Functions (Setting)
Physics:SetPosition(Target:Vector3):Physics -- Sets the object position.
Physics:SetSpeed(Target:Vector3):Physics -- Sets the object velocity.
You can chain functions, like for example:
Physics:Attract(Vector3.new(0,10,0),.2):Slow(.2):SetPosition(Vector3.new(0,0,-10))
And, here’s an example function for all of you:
local Physics=Physics.new(Vector3.zero,Vector3.new(0,.5,0)) -- Create a physics object
while task.wait()do -- Repeat forever
for i,x in {Vector3.new(0,10,0),Vector3.new(0,10,25)}do -- in both positions
Physics:Attract(x,math.max(1-((x-Physics.Position).Magnitude/1000),0)*.02) -- attract to them, far objects doesnt get attracted.
if(Physics.Position-x)<5 then -- if too close
Physics:Destroy() -- destroy object
break -- break loop
end
end
Physics:Update():Slow(.0002) -- update loop and slow object down.
-- you can set a part's position to Physics.Position
end
Give me your feedback on what do you think of this module!