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 beeboks · Dec 13, 2014 at 02:32 AM · physicsrigidbodygravityaddforce

How can I match Unity's gravity implementation per object?

Hello, I have a character that needs to change gravity and I'm trying to duplicate how Unity is applying gravity since the character has to use a consistent gravity speed as the other rigidbodies in the scene, but is not using the same direction.

In my rigidbody, I unchecked "Use Gravity" and in my code I added the line:

 def FixedUpdate() {
     rigidbody.AddForce(gravity * gravityDirection.normalized);
 }

where gravity is the same number as the one found in the Unity Physics settings (9.81). This makes the gravity a lot lighter than how Unity is applying it, though. I don't know the exact number, but I played around with multiplying the gravity in code and it seems if I do:

 rigidbody.AddForce(gravity * gravityDirection.normalized * 4.0);

it is closer to Unity's gravity setting, but it's still not exact.

How can I implement gravity in my FixedUpdate function so that it matches Unity's internal rigidbody implementation exactly?

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 Kiwasi · Dec 13, 2014 at 02:37 AM

Unity's implementation of gravity is pretty close to earths, at least at low speeds :) This means that 9.81 N of force is added for every 1 kg of mass in the object.

Teasing aside here is an answer for you.

 rigidbody.AddForce(gravity * gravityDirection.normalized * rigidbody.mass);

Googling classical or Newtonian physics will also help with the implementation. PhysX pretty much implements Newton and noting else.

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 beeboks · Dec 15, 2014 at 04:56 PM 0
Share

Perfect! Thanks!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers

Setting a RigidBody's velocity messes with my custom gravity, not sure how to proceed. 0 Answers

Gravitational pull without losing speed 1 Answer

Rigidbody (with Box Collider) falls through floor 1 Answer

How to re-center a Rigidbody isKinematic object after adding force to it? 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