• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sean_The_Ripper · Nov 30, 2010 at 11:21 PM · javascriptphysicsgravity

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;
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

How do i stop rigid bodies jumping? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

hit.rigidbody.useGravity problem? 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Show "Score:5" on my screen, how? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges