Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges