Planetary gravity for not so round object?

I tried to use the FauxGravity scripts ,but they only work on perfectly spherical planets. I am trying to override the unity 3d built in physics to create physics for the player to stand on an object like a planetoid. It is not perfectly circular so the script doesn’t work. Does anybody have any scripts or tips on how I could get a good gravity system like that to work?

I could just create my own movement functions in the script that controls the gravity to create a whole new physics and movement system. What do you think. It would be easier to make the walking forward and everything.

Assuming you don’t have corners on that not-so-round object, the way to achieve that would be by applying the gravity in the opposite direction of the normal of the surface you’re walking on.

You’d have to store the normal every frame, to adapt to the planet’s curve and then, raycast in that direction, updating the normal and apply gravity in the opposite direction of that new normal

private Vector3 _lastNormal = Vector3.up; //This line assumes you're first frame normal is looking upward
private Vector3 _velocity;
public float gravity;


private void FixedUpdate () {
    RaycastHit hit;
    if(Physics.Raycast (transform.position, -_lastNoraml, out hit, 10f, ~(1 << LayerMask.NameToLayer ("MyPlanetLayer"))) {
        _lastNormal = hit.normal;
    }

    _velocity += gravity * -_lastNormal * Time.deltaTime;
    _transform.position += _velocity * Time.deltaTime;
}

I didn’t test this code, but the idea of it is relatively obvious. Your turn to adapt it