Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by murkertrer · Jun 21, 2016 at 03:17 AM · gravityaddforceforce

Newtonian Gravity working backwards

I'm trying to make a planet affect other objects.

It kind of resembles artificial planetary gravity, but it is wierd, because the farther the object is, the more force it excerts. Perhaps there is something wrong with my formulation?

 Vector3 direction = rbUnderInfluence [i].transform.position - transform.position;
 
 intensity = gravitationalForce * (rb.mass * planetMass / distance * distance);
 
 rb.AddForce (direction * intensity);
 
Comment
Add comment · Show 1
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 JDAUL · Jun 21, 2016 at 03:39 AM 0
Share

How are you calculating your distance? I suspect that may be where the issue is, try tracing it out and see if it is behaving as expected.

1 Reply

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

Answer by Bunny83 · Jun 21, 2016 at 03:55 AM

You have two errors here:

  • This planetMass / distance * distance will be equal to planetMass. Division and multiplication have the same precedence. Operators with same precedence are executed left to right. You would need to put your "distance * distance" into brackets.

  • The second problem is that you use your direction vector directly. This vector has a "length". The further away your objects are, the "longer" / greater the vector is. You have to normalize the vector.

All in all this should work:

 Vector3 direction = rbUnderInfluence [i].transform.position - transform.position;
  
 intensity = gravitationalForce * rb.mass * planetMass / (distance * distance);
  
 rb.AddForce (direction.normalized * intensity);


Note that using real world values will most likely create huge errors due to the large numbers.

Finally instead of your distance * distance you could simply use direction.sqrMagnitude. It's the distance / length of the direction vector squared.

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 murkertrer · Jun 21, 2016 at 11:20 AM 0
Share

Thank you, very usefull.

The only thing is that I had a very strange behaviour, when I wrote (distance * distance) I was not getting any result, so I just did the multiplication before and places it where the distance was before.

Also, as you mentioned, I ended up tweaking the gravitationalforce almost to 1000 so that it acted in accordance to the world values,

Thank you again.

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

45 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change rigidbody's jumping speed 2 Answers

Applying force to my object has no effect. 1 Answer

Applying force to a rigidbody 2 Answers

Rigidbody--Addforce on a Spherical Platform(A Globe) 2 Answers

Simulate gravity on rigidbody 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