- Home /
How to make a character walk on a 3D cube planet and a long 3D cube planet using gravity?
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 https://www.youtube.com/watch?v=gHeQ8Hr92P4 . I want the character walk the same way but instead of a sphere it should be a cube and a long cube.
Answer by coolbudy1998 · Aug 08, 2018 at 06:16 PM
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 -https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/moving-player
If I understood our question correctly then this will surely help you. Fine?? :-)
Answer by Eno-Khaon · Aug 09, 2018 at 12:48 AM
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.
Your answer
Follow this Question
Related Questions
Unity 2D Cube Planet Gravity 0 Answers
Creating 3d planets with terrain and atmosphere 3 Answers
3D Planatary Gravity 2 Answers
Walking & Gravity 2 Answers
Attaching an Image to a 3D Cube 2 Answers