i’m stumped on this part of my code because it’s pourpose is to move an object to the closest planet, but if one planet is very big and a small planet is next to it, while the player is walking on the bigger planet, the smaller planet pulls the player towards it because the player was closer to the center of the smaller planet than to the bigger planet it was on. how do i make it so it orders the array by how close it is to the surface and not to the center?
If your planets have SphereCollider, you can use SphereCollider.radius and substract it from the distance between you and the center of a planet. As following:
As a sidenote, please don’t do this every frame. GetComponent could seriously slow down your update loop. I recommend caching that in some way. Also, some other optimizations could be replacing your Distance with a squared Distance
(obj1.position - obj2.position).sqrMagnitude
This means you don’t have to calculate the root of the sqrMagnitude every frame (slow).