I am currently making a game in space, and I want to some semi-accurate gravity, such that objects are pulled to the center of the various planets and stars.
I already attempted to implement this, like so:
public void ApplyGravity()
{
if (AffectedByGravity && Moves)
{
Body Apply = SystemDatabase.Get(UniversePosition).GetSOI(gameObject.transform.position);
float Gravity = (float)Apply.Gravity(Vector3.Distance(gameObject.transform.position, Apply.Position));
Vector3 Direction = (Apply.Position - transform.position).normalized * Gravity * Time.deltaTime;
rigidbody.velocity += Direction;
Distance = Vector3.Distance (transform.position, Apply.Position);
}
}
However, when the player actually contacts the body it is being attracted by, it sort of bounces up and down rapidly, so it almost looks like you are in a jackhammer, which is the problem I’m trying to fix.