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 Tuah · Oct 01, 2010 at 06:38 PM · gravityuniversalplanetrelativequack

Gravity and the Physics Manager.

So I'm working on a planetary gravity system, and I can do it really well through script if I want.

But I wonder if there might be a more universal shortcut. I notice a "Gravity" vector in the Physics Manager. You think there might be some way to make gravity separate for separate objects, still using the "Use Gravity" variable?

Otherwise, I'll have to make all my objects share a universal gravity script, but I find that to be a little hard to keep track of for eeeeeverything.

On that note, I'm using Unity 2.6.1.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by skovacs1 · Oct 01, 2010 at 09:36 PM

I'm fairly certain it's an all or nothing sort of thing. If Rigidbody.useGravity=true, the Rigidbody will be affected by the Physics.gravity Vector3.

If you were to try changing Physics.gravity at run-time, you would likely get un-predictable results depending on when things are applied and you would still need to iterate through each of the other gravitational bodies just to calculate the gravity acting on the current body anyways because gravity is a direction, not a point in space.

You would really need to either:

  1. Have a global script that tracks and applies all gravity calculations,
  2. or have a script on each of the gravity-affected bodies which applies calculations to that body

The global script could be optimized to do fewer calculations through the use of jagged loop iteration:

//isn't this like O(nlogn)? It's at least better than O(n^2)
for(var i : int =  0; i < objects.length-1; i++) {
    var object1 : Rigidbody = objects[i];
    for(var j : int = i + 1; j < objects.length; j++) {
        var object2 : Rigidbody = objects[2];
        var force : Vector3 = calculateGravity(object1, object2);
        object1.AddForce(force);
        object2.AddForce(-force);
    }
}

whereas the per-body script would need to iterate through everything that could act upon it:

//O(n^2) because this is done for every object and it performs on every other object
for(var other: Rigidbody in otherObjects)
    transform.AddForce(calculateGravity(other));

It's really not that much to keep track of if it's just gravity.

Comment
Add comment · Show 1 · 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 Tuah · Oct 02, 2010 at 02:51 AM 0
Share

I figured there wouldn't be any easy solution, but it doesn't hurt to ask. :P

I think I'll simply set the planet to apply a gravitational force to any players or objects within the Trigger area. That'll be a pain getting the character stable through it all, but it'll be worth it to create such a universal system.

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

No one has followed this question yet.

Related Questions

walking around a spheroid planet centered at the origin 1 Answer

Planet gravity help need guidance no code 1 Answer

Why do the characters jitter at some places? 0 Answers

How to rotate a player when using Mario Galaxy style gravity? 5 Answers

Fully understanding the gravity of the situation 2 Answers


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