Spherical Gravity?

Ok I really want to make my terrain a sphere/globe of sorts and I don’t want my player falling off when he gets to the “edge”. In other words I would like him to start walking from point A), and continue in a straight line to end up back at point A).

So can anyone point me in the right direction because I’m not even sure how to ask the question properly.

Thanks in advance!

Make sure rigidbody.useGravity isn’t enabled, create a script attached to an empty game object at the center of the planet, and then have that script increase the velocity of everything on the surface of the planet using this formula:

object.rigidbody.velocity += (transform.position - object.transform.position).normalized * gravity * Time.deltaTime;

The above will cause gravity towards the center of the planet using acceleration gravity per second.

http://forum.unity3d.com/viewtopic.php?t=9476&start=13

–Eric

Awesome response time guys, sorry I’m so late getting back to you.

Unfortunately my programming skills are weak at best.

Gargerath, I was able to follow your instructions (I think…) but not sure if I created the script properly as all it accomplished was errors.
P.S. nice to see a fellow missourian. :slight_smile:

Eric, thanks for the link. I was able to open the faux gravity file uploaded by AaronC that put the scipts into their proper places but once again Im not sure how I am applying these or if they work because they are not the same as the scripts posted by podperson at the top of the thread or something else altogether?

Also I am modeling the planet I am using, in maya. Not sure if that changes anything. I just want to apply the physics for my universe to this planet and I need a center of gravity.

Eggpoacher+programming= #@%$@(!%#)_!%#

For mine, you need a variable called object of type gameObject that you apply velocity to. Ideally, my code would be in this function:

function OnTriggerStay(hit : Collider) 
{
   if (hit.transform.tag != "Planet") {
      var object : GameObject = hit.gameObject;
      object.rigidbody.velocity += (transform.position - object.transform.position).normalized * gravity * Time.deltaTime; 
   }
}

You’ll need to tag all things you don’t want affected by this gravity with the tag “Planet.”

If it causes errors, just post which ones you’re getting and the code. I’m sure people will be glad to help you fix the issues.