- Home /
Other - Asker request
How can I accelerate a rigidbody towards another at X m/s?
I cant figure out how to accelerate one rigidbody (rigidbody A) towards another (rigidbody B) at a rate of X m/s WITHOUT rotating rigidbody A towards rigidbody B. X would exponentially decrease as the distance increases, like gravity, and completely stop after a configurable distance, perhaps using Physics.OverlapSphere. I also only want to have to add the script to rigidbody B. Any help is appreciated, I am new to unity.
I also only want to have to add the script to rigidbody B
I don't know your setup or goals, but doing it this way makes your code pretty ugly.
X would exponentially decrease as the distance increases
Consider a linear rather than an exponential decrease. It may feel/look better to the user.
@robertbu, the reason it has to be exponetial is because i am making a realistic space flight simulator, similar to $$anonymous$$SP and looks/feels are second to realism in my project. As for me only applying the script to rigidbody B, i dont want to have to add it to every other object
in update:
transform.rigidbody.AddForce((locationA-locationB) * $$anonymous$$assOfThing)
and depends what you consider a meter
If you looking for realism then you'll have to have realistic scale and mass. Here is a link about planetary gravity:
http://answers.unity3d.com/questions/359759/how-to-program-gravity-for-planets.html