Attraction by object shape (gravity)

Hello,
is there a chance that the player was attracted by the shape (mesh)?

for example: when you reach the edge of the cube you can go off the wall without falling and then go to the bottom of the cube (upside down).

If so, how do I do that?

You will need a rigidbody character. I wrote a script times ago that allowed a rigidbody to walk upright over any surface - a local gravity pushed it towards the mesh under its feet, including in vertical or totally upside down surfaces. Take a look at my answer in this question.

I just wrote this up without testing so take it with a grain of salt:

Ray ray = new Ray(Vector3.zero, Vector3.forward);
RaycastHit hitInfo = new RaycastHit();
if(Physics.Raycast(ray, out hitInfo) )
{
    Vector3 hitNormal = hitInfo.normal;
}

What you could do is do a raycast towards the center of the cube and find the normal of the raycast hit like I show above. And then gravity = -hitNormal;

The gravity will always take your character towards the face of the cube he’s standing on and if he falls off the edge it will take him above another face to stand on.

This “should” work for other shapes too.

Is this for a “minecraft planet”? I have to ask because I’ve wanted to see one. Without the motivation to actually do it :stuck_out_tongue: