- Home /
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;
}
}
Answer by puckipedia · Mar 05, 2011 at 03:43 PM
You cant use an CharacterController with a Faux Gravity, because the CharacterController will work like it has no RigidBody.
Answer by Gruffy · Dec 19, 2013 at 02:16 PM
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
Your answer
Follow this Question
Related Questions
Show "Score:5" on my screen, how? 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Realistic Bouncing Effect 1 Answer
How do i stop rigid bodies jumping? 1 Answer