Exploring the planet
Now that we have generated a planet, it would be awesome if we could explore the surface of it. As a fun bonus, we will add a first-person-view controller, so we can explore our planets. Fortunately for us, someone has already tackled the problem of spherical gravity in Unity, so all we will have to do is plug and play.
You can get the script for this section either from the example files or from its source at https://github.com/SebLague/Spherical-Gravity by SebLague. There is also a video at that location where you can see how the scripts work. The scripts that are included are the FirstPersonController.cs
, GravityAttractor.cs
, and GravityBody.cs
.
You are welcome to view the video to get an explanation on the code in these scripts. We are just going to plug them in and use them as they are, though. You'll want to add the GravityAttractor
script to the Water
object. Set a tag for the Water
sphere to Planet
. Then, create a capsule for our first person controller by...