- Home /
Finding "UP" while using planetary gravity?
I am trying to create planets and I have the gravity figured out, but whenever my character walks beyond a certain point, it is no longer grounded and the character just falls. So how do I find the normal direction for a planet so that I can have my character walk on the planet? Thanks!
I can't help you personally, since I too am having difficulty with gravity, but have you checked this video out? He seems to do what you're looking to do, and his tutorials are pretty reliable.
Yeah I have seen that tutorial, but the problem with it is that I want there to be the possibility of having say three players on one planet.
Also if you would like some help with gravity you can use my script. It's only a slightly modified version of a public script anyways.
wouldn't it just be :
planetaryPull = ( player.position - planet.centerOfGravity.position ).normalized * -1.0 * gravity; // assu$$anonymous$$g gravity is a positive value
Besides this being off topic, here is the script that I am using:
using UnityEngine;
using System.Collections;
public class Gravity : $$anonymous$$onoBehaviour {
public float range;
public Collider[] objects;
void Start ()
{
}
void Update ()
{
objects = Physics.OverlapSphere(transform.position, range);
float force = rigidbody.mass / 100;
foreach(Collider c in objects)
{
Rigidbody rb = c.attachedRigidbody;
if(rb != null)
{
if(c.gameObject.tag != "Planet")
{
Vector3 offset = transform.position - c.transform.position;
rb.AddForce(offset / offset.sqr$$anonymous$$agnitude * rigidbody.mass * force);
}
}
}
}
}