# Faux Gravity Prolem? #2

(if needed, the faux gravity body script is in the question "Faux Gravity Problem?")

Hello again! i got my faux sripts working exccept for one thing. my player keeeps falling off my sphere and wont walk around my "planet" right. i equiped a rigidbody to it and a charctercontroller so it can move around(i have a seperate moving script for this). Could someone help me out with this one? Thanks!

Script Faux Gravity Attractor( I attached this to the "planet"):

// Set to true for mono-directional gravity
var useLocalUpVector : boolean = false;

// Force applied along gravity up-vector (negative = down)
var fauxGravity = -10.0;

function Attract ( body : FauxGravityBody ){
var gravityUp : Vector3;
var localUp: Vector3;
var localForward : Vector3;
var t : Transform = body.transform;
var r : Rigidbody = body.rigidbody;

// Figure out the body's up vector
if(useLocalUpVector){
gravityUp = transform.up;
} else {
gravityUp = t.position - transform.position;
gravityUp.Normalize();
}

// Accelerate the body along its up vector
r.AddForce( gravityUp * fauxGravity * r.mass );
r.drag = body.grounded ? 1 : 0.1;

// If the object's freezerotation is set, we force the object upright
if(r.freezeRotation){
// Orient relatived to gravity
localUp = t.up;
var q = Quaternion.FromToRotation(localUp, gravityUp);
q = q * t.rotation;
t.rotation = Quaternion.Slerp(t.rotation, q, 0.1);
localForward = t.forward;
}
}

You cant use an CharacterController with a Faux Gravity, because the CharacterController will work like it has no RigidBody.

The order is to apply the Gravity Attractor type script to an empty/sphere GameObject that can sit at the centre of your planet, with this you can then add the Faux Gravity Attractor script to that GameObject.

You must then simply add the faux gravity body script to your player.

In the Gravity Attractor script you should be able to assign a value to a gravitational pull - make this about 50 or something.

If both scripts are attached to the correct objects, you should not get any problemsâ€¦
I rearranged this script to C# (which is a better language for Unity scripting IMHO)
I can send you my C# scripts in a package with scenen if you are still interested but i just noticed the date this was askedâ€¦whoops
Gruffy