- Home /
Next time include code which demonstrates that you tried it for yourself.
Gravity on a cube. walking around the cube like youd walk around the globe, you dont fall off the earth--you dont fall off the cube..
So ive asked this question before but each time i get a pretty useless answer because im apparently not being specific when i say i want gravity on a cube--i want to walk around the cube like youd walk around a sphere--i DO NOT want to fall off The cube is a sphere except flat it has 6 sides and each side will have something on it, for example a house on each side, i want to walk into each house and say hi to the people in there and ask for a cup of sugar. i do not want to fall off this cube, i dont want to jump off this cube, i want to walk around it, let me say it again, i. want. to. walk. around. my. cube. i dont care how its done, i want to walk around a cube. ive applied a rigid body to it like someone had suggested but low and behold i fell off so obviously this method doesnt work or it was poorly and half assed explained. i dont know how i can be more specific then this, if for whatever reason this isnt specific, give it another read and use a bit more imagination. Im not being rude, ive asked the same question 5 times and i get either nothing or people looking it in black and white saying i wasnt technical enough. well im new give me a break and help me out.
"Im not being rude" Well, that's a matter of opinion....
Rather than ask the same question five times and demand people read it again and use more imagination than the "half assed" explanations that have already been offered, why not describe what effort you've put in to solve your problem?
Answer by Graham-Dunnett · Jul 27, 2015 at 11:00 AM
Gravity in Unity assumes that your game is running on a flat terrain. So typically the ground is in the xz plane, and gravity is acting in a negative y axis. You're using a terrain that is 6-sided on a cube. You will need to adjust the gravity direction each time your character moves from one cube side to another.
Answer by Ellenack · Jul 27, 2015 at 04:46 PM
I woulg go like Graham Dunnett said. In pseudo-code, you would get something like that (in 2D for a simple explanation) :
vec2 playerPos;
vec2 cubeCenter;
vec2 playerDir = (playerPos-cubeCenter).normalized; // player position relative to the cube
if( abs(playerDir).x > abs(playerDir.y) )
{
// The player is on a face on the left or the right
if( playerDir.x > 0 ) // right
gravity = ( -1, 0 ) // gravity push him left
else // left
gravity = ( 1, 0 ) // gravity push him right
}
else
{
The Player is on a face on the top or the bottom
if( playerDir.y > 0 ) // top
gravity = ( 0, -1 ) // gravity push him down
else // bottom
gravity = ( 0, 1 ) // gravity push him up
}
However, beware the corners, it might need a little tweaking to go through them correctly (a lerp of the gravity so he start falling and then touch the ground for a nice effect)
Answer by meat5000 · Jul 27, 2015 at 04:10 PM
Start with a sphere for conceptualising.
Apply a 'downward' force from each Object to the centre of the World depending on its orientation. Switch Gravity field off.
When that works switch to a cube and adjust as needed (by moving where the object 'thinks' the centre is).
Its easy.
Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
Script error HELP 1 Answer
Raycasting to the bottom side of a plane? 2 Answers
More Realistic Physics 1 Answer