Coding a black hole

Hi all.

I’m creating a top-down game set in space, and for one of my levels the basic premise is avoid the black holes. However, instead of merely having sphere colliders, I’d like to add in the effect of the player getting sucked toward the black hole, if at all possible.

I’m relatively new to coding, and I have no idea where to start. I’ve checked here for answers, but I think my request is too specific, and my coding capabilities aren’t up to the task of chopping and changing different code.

Thanks again

I don’t think you are after the perfect black hole and all of its calculations because if you were you would work for NASA and you would not need us.

So all you need is take the distance and divide the max force by that distance squared.

float maxForce = value;

public void BlackHoleForce(Rigidbody rig){
   float distance = Vector3.Distance(blackHole.transform.position, rig.transform.position);
   float force = value / (distance * distance);