I searched for hours for an answer but there aren’t so many answers about this topic that can help.
I am planning to create different planets with different shapes so i would like to know how to code to make a character walk on a cube and a long cube planet in 3D using gravity. Can anyone help me, please?
Edit: explaining what I am looking for is that based on this video Unity Tutorial: Faux Gravity (walk on planets) - YouTube . I want the character walk the same way but instead of a sphere it should be a cube and a long cube.
It’s simple…just add rigidbody and box collider to both of your objects (planet and your character). Tick the “gravity” and “is kinematics” in them.
This will enable your character to stand on the cube.
Now the next part is movement.
This part is easily available on net. You can check more on here -Environment and Player - Unity Learn
If I understood our question correctly then this will surely help you. Fine??
In the example video, they used a spherical surface for the easiest implementation. The “gravity” applied per frame pulls the target toward the object/sphere’s center.
In order to expand this into more shapes, you need a new “down” for your gravity. The most straightforward way to find your new “down” is to have your character fire a RaycastAll() downward (relative to the character, so -transform.up). When the raycast hits valid ground (hence using RaycastAll() to filter potential targets), use the normal to determine gravity’s up/down.
This will be much more work to implement cleanly, especially once you’re reaching the edge of a cube. You’ll need to ensure that you properly transition between sides, so you can’t rely exclusively on the single Raycast downward.