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
0
Question by Static-Dynamo · Sep 08, 2016 at 08:32 AM · physicsrigidbodyvrgravitysimulation

Handling Large number of Active Rigidbody Evaluations

Background As a side project a friend and I have been developing a solar system simulation for the vive. We are using the Steam VR plugin. We are targetting 64bit PCs and the Vive. We have created our own scripts to create a point based gravity system that enables us to define a gravitational force centered on any game object of our choosing. The simulation starts with a single gravity well existing in the scene and the user can add items to the scene of various masses and velocities and watch them interact with the gravity well.

Problem We can get up to about 500+ active rigidbodies (all using primitive sphere colliders) before things begin to slow down. Every fixed update we gather the gravitational force that needs to be applied to these rigidbodies and then use addforce to adjust their trajectories accordingly. To be honest this works just fine for what we want but for our next step we begin to run into serious problems. I.E. Ideally instead of a single gravitational source (the "star" in the center of the scene) we want ALL rigidbodies in the scene to also have their own gravity, based off of their mass. Our current scripts allow for this, but turning this functionality on causes a huge drop in the number of items we can have in our scene before slowdown. We drop down to about 100-150 and even then it can be problematic. It is pretty obvious what's happening, both in theory and from the profiler- the evaluations we are doing balloon to a huge number because now we are evaluating the amount of force to add, multiplied by the number of items in the scene, for each individual rigidbody.

Question Can anyone point me in the right direction on how to possibly optimize a scene like this? I would like to get back to about 500 active rigidbodies if possible, while allowing all these items to have their own gravity as well. The ideal scenario would be to observe these items coalescing into "chunks" in the same way planetary bodies accrue from masses of smaller particles circling a gravity well. I am doing what research I can, but in actuality I am an animator and artist who dabbles in programming so any assistance would be a great help (currently trying research and learn if it would be possible to somehow offload all these calculations to the gpu).

Apologies for the wall of text, I can provide messy samples of code if you like. Thanks for reading.

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
0

Answer by doublemax · Sep 08, 2016 at 09:09 AM

http://gamedev.stackexchange.com/a/19394

It seems that you're doing the gravity calculations yourself. Have you tried letting Unity do it for you?

Apart from the trick in the above post, if you wanted a "real" simulation, you'd usually use the GPU to do the calculations with OpenCL, CUDA etc. I don't know what Unity does internally, but as it uses PhysX, which uses the GPU, maybe the force calculations take advantage of that. Might be worth a try.

Comment
Add comment · Show 5 · 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 Static-Dynamo · Sep 08, 2016 at 12:08 PM 0
Share

That grid idea you linked is a great idea I will research it more. thank you!

As for letting Unity do the gravity calculations, I'm not sure how that would be possible. From everything I've looked up about it, Unity is only capable of doing gravity along a single vector, like in the project settings where it lets you set the Vector3 for the gravity direction.

While this is useful for the majority of use cases I need my gravity to be point based. So the vector along which the force is applied is dependent on both the object's location and the location of the gravity source. If there is a way to get Unity to do gravity from a discrete point in space rather than along a single vector that could be very useful.

As for using the GPU for calculations, the problem I am running into is that I need to be able to add and remove items from the simulation at will and everything I have seen so far uses a given set of items. But I will continue to look, also GPU simulations seem like a completely foreign language and are not well documented in a way that I can easily understand. I'll keep at it. Thank you for your suggestions.

avatar image doublemax Static-Dynamo · Sep 08, 2016 at 12:14 PM 0
Share

As for letting Unity do the gravity calculations, I'm not sure how that would be possible. From everything I've looked up about it, Unity is only capable of doing gravity along a single vector, like in the project settings where it lets you set the Vector3 for the gravity direction.

Sorry. I'm still a relatively new Unity user myself and didn't realize that. I guess the grid idea is really your best option then.

avatar image doublemax Static-Dynamo · Sep 08, 2016 at 03:54 PM 0
Share

If you want to research any further, Googe for "Unity Compute Shaders Gravity" . There are some impressive videos out there:

https://www.youtube.com/watch?v=_UBHG2cDD7g

https://www.youtube.com/watch?v=3Wu4Wo9HC0c

https://www.youtube.com/watch?v=Hz42sDJE2e4

avatar image tanoshimi · Sep 08, 2016 at 04:26 PM 1
Share

Just to correct one point - Unity's PhysX does not use the GPU - it runs on the CPU. https://blogs.unity3d.com/2014/07/08/high-performance-physics-in-unity-5/

avatar image doublemax tanoshimi · Sep 08, 2016 at 04:32 PM 0
Share

I see. Thanks for the info.

avatar image
0

Answer by jmonasterio · Sep 08, 2016 at 05:47 PM

Keep in mind that the effect gravity is inversely proportional to the SQUARE of the distance.

This means that when deciding which objects affect each other, you can probably safely ignore small objects that are far away.

For example, the sun is affected by pluto's gravity, but it doesn't really matter unless you need an extremely accurate simulation.

So you could just focus on nearby objects and big objects, when calculating the effect of gravity on a particular object.

This could greatly reduce the number of calculations, which will allow you support more objects.

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

106 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 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 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

Applying proper drag and center of mass for a vehicle 1 Answer

ConfigurableJoint Target Position/Rotation Issues? 1 Answer

When and when not to use kinematic rigidbody? 2 Answers

How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers

How can I turn on/off Rigidbody.useGravity? 0 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