Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Mark Benitez

Faux Gravity (walk on planets)

Recommended Posts

 

A tutorial on creating a Faux Gravity system in Unity. This allows your characters to walk on planets without falling off. (As seen in Mario Galaxy)

Download planet model:Please login or register to see this link.
Download Unity project:Please login or register to see this link.

  • Like 3

Share this post


Link to post
Share on other sites

final outcome looks pretty sweet. Not sure what I'd use this for, but honestly looks good. Thanks for the post.

Share this post


Link to post
Share on other sites

@rabassa the concept is super simple. If the links don't work, you can just code your own fairly easily. If I'm not mistaken (you never know, I'm just typing it up real quick on my phone), the basic concept is just:

 

transform.LookAt(planet.position);

transform.eulerAngles += transform.left * 180;

 

And that sets the orientation of the player. Then you just use the normal movement code like this one liner (doesn't account for jumping)

moveDirection = transform.TransformDirection(Vector3(inputX, gravity, inputZ) * moveSpeed * Time.deltaTime);

 

 

so the final understanding is, lookat the center of the planet, rotate the player on its local x axis 90 degrees. Then all the movement is handled locally, like normal everyday character movement. It's not really rocket science by any means

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×