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]
else
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
end
newP.Position = NextPos
local dis = (previousPos - Sun.Position).Unit
local force = 100
velocity = (NextPos-previousPos).Unit*magnitude
previousPos = NextPos
end
end)
I think it might be related to the gravity but i am not sure