Now that's all out the way, you can do a very simple approximation by doing something like var currentPos = _rigidBody.position Satelite.GetComponent().AddForce(forces, ForceMode.Acceleration) ForceMode.Force divides the force by the mass of the rigidbody it is applied on. Or better yet, assuming Mass is the mass of the satellite, and gravity is not a general constant, but just the local gravity of your planet. Satelite.GetComponent().AddForce(forces, ForceMode.Force) What you want here is to switch to ForceMode.Impulse, or remove the deltaTime. ForceMode.Force already multiplies the Force by ltaTime. Now that the code is much simpler, I can find a crucial mistake. You can further reduce it by doing: var distance = sateliteCords - planetCords Here's what your code is actually doing: var sateliteCords = ĭistanceFromSatelite = distance.magnitude įorces = distance / distanceFromSatellite * -F I'm a bit of a noob when it comes to physics simulations so can one of you geniuses please help? I read somewhere that I need a copy of the solar system running independently form the unity updates, and calculate the rocket trajectory from there but I don't know how to approach that. I have tried "speeding up the simulation" with Time.timeScale = 50 but it isn't fast enough. Satelite.GetComponent().AddForce(forces * ltaTime, ForceMode.Force) īut I don't know how to predict future points in time to give me the orbit shape. Var distance = sateliteCords - planetCords ĭistanceFromSatelite = Vector3.Distance(, ) į = (Gravity * Mass) / Mathf.Pow(distanceFromSatelite,2) įorces = (distance / Mathf.Sqrt(Mathf.Pow(distance.x, 2)+ Mathf.Pow(distance.y, 2)+ Mathf.Pow(distance.z, 2))) * -F I have managed to get realistic physics and orbits when adding gravitational forces to a rigidBody: var sateliteCords = I am trying to make a game with Unity that uses rockets that are in orbit and can transition to different planets, but I need to predict the rocket path in real-time, depending on the current velocity/direction of the rocket allot like spaceflight simulator does.
0 Comments
Leave a Reply. |