0

I have searched for a answer and have not found one yet. I have a elliptical Orbit path, and I'm wanting to move the orbiting body around the path in 3D space. Current attempts have not worked right. (object slows at periapsis and speeds up at apoapsis, or just breaks, with NaN values)

Available Values are: Semi major, semi minor, velocity, periapsis, apoapsis, Current orbiting body position in Degrees or radians, and both masses + distance.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • see [Is it possible to make realistic n-body solar system simulation in matter of size and mass?](https://stackoverflow.com/a/28020934/2521214) look at bullet **#2** the 2 links there are what you are looking for ... there are 2 approaches however ... either using Kepler or Newton d'Lambert ... which one depends on the app you are doing... are the orbits stable? or you got some space ships and want to apply thrust, gravity assists etc ? – Spektre Dec 17 '18 at 09:20

1 Answers1

0

More information will be helpful. But I recommend you use unity built in rigidbody component. You need to get the center of mass of the body you're orbiting and his mass than calculate the G force for the distance between the centre of mass of the body you're orbiting to your centre of mass more on that here https://www.physicsclassroom.com/class/circles/Lesson-3/Newton-s-Law-of-Universal-Gravitation than take that vector and multiply it by your direction. This function will help you to do that https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html After you got your direction multipled by your force use RigidBody.AddForce() and send your vector. I suggest using Physics.OverlapSphere() for that task see https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html And putting all of this logic on the body you're orbiting. Than all you need to do is get the body you want to orbit to be in the right spot with the right velocity and you'll get your results. Just make sure to turn off gravity and get your mass right

tomer zeitune
  • 1,080
  • 1
  • 12
  • 14
  • Yes I found that way very effective. But I need it to be in a system to where I can "update" a said system to current the current time, in order to save on cpu. I have tried finding a way to find the desired orbit position in degrees / radians threw ellipse arc lengths, which seam to work although it breaks or jumps. https://keisan.casio.com/exec/system/1343722259 Is where I got the equation tho I think I may have used it wrong. I also reversed it to find 1 of the angles instead of the arc length. But like I said it breaks when executing. – Chief65 Dec 09 '18 at 22:10
  • double x = Math.Abs(Math.Sqrt(Math.Acos((Math.Pow(Math.Sqrt((_Orbit.SemiMajorAxis - b) / _Orbit.SemiMajorAxis), (v + _Orbit.SemiMajorAxis * Math.Log((Distance * (_Orbit.OrbitPosition * (Math.PI / 180)) * Math.Cos(_Orbit.OrbitPosition * (Math.PI / 180))) / _Orbit.SemiMajorAxis, Math.Sqrt((_Orbit.SemiMajorAxis - b) / _Orbit.SemiMajorAxis))) / _Orbit.SemiMajorAxis)) * _Orbit.SemiMajorAxis) / Distance)); This Works Perfectly although like I said it breaks after a second or so. – Chief65 Dec 09 '18 at 22:30