Orbit script problem

I am trying to shows the planet orbit around another part but the script i made isn’t really accurate,
and i use a LineForce with a magnitude of 100 to simulate the gravity and use a trail to show the real part trajectory

I couldn’t really find any solution or help on the dev forum except this post Orbital trajectory problem but didn’t really got any answer to my problem

I currently have this

local Planet = game:GetService("Workspace").Planet
local Sun = game:GetService("Workspace").Sun

Planet.AssemblyLinearVelocity = Planet.CFrame.RightVector*100

local dots = {}

game:GetService("RunService").Stepped:Connect(function(t, dt)
	local velocity = Planet.AssemblyLinearVelocity
	local previousPos = Planet.Position
	local magnitude = velocity.Magnitude

	for i=1, 200 do
		local Gravity = (Sun.Position-previousPos).Unit*100 -- 100 is the force from the line force

		local NextPos = nil

		NextPos = previousPos+velocity*dt+Gravity*dt*dt

		local newP = nil

		if dots[i] then
			newP = dots[i]
			newP = Instance.new("Part")
			newP.Size = Vector3.new(.5, .5, .5)
			newP.Material = Enum.Material.SmoothPlastic
			newP.Color = Color3.fromRGB(85, 170, 255)
			newP.Anchored = true
			newP.CanCollide = false
			newP.Parent = game:GetService("Workspace")

			dots[i] = newP

		newP.Position = NextPos
		local dis = (previousPos - Sun.Position).Unit
		local force = 100
		velocity = (NextPos-previousPos).Unit*magnitude
		previousPos = NextPos


I think it might be related to the gravity but i am not sure

i figured it out by myself by just applying the gravity and multiplying the result by pi

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