Custom Gravity issues

I am attempting to apply custom gravity to all objects in my game. to start with all the objects should have standard (0,9,0) gravity, but as the game goes on the player has the ability to set a new ‘Down’ direction for themselves or any item/other player

so far I have


 public class GravityScript : MonoBehaviour {
	public Vector3 GravityForce;
	public Vector3 tempGrav;
	Vector3 newUp;
	Vector3 CoG;
	// Use this for initialization
	void Start () {
		this.rigidbody.useGravity = false;
		GravityForce = Physics.gravity;
		CoG= this.transform.position+this.transform.up;
		Vector3 newUp = this.transform.up;
	// Update is called once per frame
	void Update () {
		CoG= this.transform.position+this.transform.up;
			RaycastHit hit=new RaycastHit();
			Ray ray = new Ray(CoG, Camera.main.transform.forward);
			if(Physics.Raycast(ray, out hit))
				tempGrav = hit.normal *-10;
			//	tempGrav = tGrav;
				newUp = hit.normal;

			GravityForce = tempGrav;
	void FixedUpdate()
		rigidbody.AddForce( GravityForce * Time.fixedDeltaTime, ForceMode.Acceleration);


it is not a simple case of inverting gravity, as it could be assigned to an angular surface. The script above only applies for modifying there own gravity, well it should I cannot seem to get it to work.

any ideas - I know I have to implement selfrighting as well - pointers on that would be good too!


how does your custom gravity work? are you using rigigbodies or id you make a script?

if script you can make a child script from it, then give a public function that changes the direction of gravity.

if rigid bodies you could turnoff gravity and rotate the gravity vector (Physics.Gravity, store it in another variable!) to the direction the player sets it.

This code serves as a guide, copying paste pasting it will probably cause all sorts of weird things(e.g character slowly being pulled through the floor, jitterbugging, poor collisions)

Vector3 grav

public void ApplyMyGravity() {

//apply manual gravity
transform.position =- grav * Time.Deltatime


public void SetMyGrav(Vector3 dir) {

 grav = Physics.gravity * Quaternion.Euler(dir);


Hope it helps