• 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
3
Question by Squeegy · Apr 22, 2010 at 08:05 PM · collisionphysicsrigidbody

RigidBody/Collider physics, or simple script?

I'm making a game that, gameplay wise, is completely 2D. A plane with 3D models on it. It's set in space with inertial physics.

My physics needs are pretty simple Newtonian stuff. An object with some mass value is applied a force of (x,y). And all objects are considered circular, so if 2 objects are within a distance of a.radius + b.radius, then a collision occurs, forces are applied to both objects and some logic is triggered.

So my question is wether it's worth using RigidBody or the various collider components or to roll my own scripted solution for these physics. It seems like RigidBody is overkill. I don't need gravity, or center of mass, or friction or 3D polygon collision detection. I just need proximity based collision detection and 2D billiard ball style newtonian physics.

And I am betting that Unity physics and colliders would make this easy, but I would pay extra for them in performance due to all the features I'm not actually using on these components that it is processing anyway.

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

5 Replies

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

Answer by Eric5h5 · Apr 22, 2010 at 08:49 PM

The built-in physics are better-optimized than what you can do in scripting. Just moving an object in a straight line is 30% faster with a rigidbody and AddForce vs. using Translate() in FixedUpdate, and that's obviously without any collision detection code or anything else. Adding collision and other features makes the physics engine increasingly faster by comparison.

Most physics features that you're not using aren't applied anyway...friction only matters if two colliders are in constant contact, so that would never be calculated in the first place. 3D polygon collision detection only applies if you're using a mesh collider, which you wouldn't be doing anyway, you'd be using sphere colliders. There's no reason not to use the built-in physics, unless you need specific behavior that those physics can't provide.

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 duck ♦♦ · Apr 22, 2010 at 09:48 PM 0
Share

Nice answer, good to hear - and I guess this settles the speculation about whether a full 2d engine like box2d would outperform unity's physics constrained to 2d.

avatar image Squeegy · Apr 23, 2010 at 01:31 AM 0
Share

So I converted my game objects to rigid bodies, and changed my manual accel/vel/pos code to use AddForce and friends and I went from 80FPS to 40 in my test scene with 1000 objects. So I think I'm going to handle my own physics but use colliders to trigger events. It's also possible that my code just wasn't too efficient since I don't know Rigidbodies very well.

avatar image Eric5h5 · Apr 23, 2010 at 02:00 AM 0
Share

@Squeegy: Could be, because any test I make has physics clearly winning the speed race.

avatar image Squeegy · Apr 23, 2010 at 08:25 PM 0
Share

After more experimenting, I found you are 100% right. With simple AddForce stuff, the difference isn't so clear, but when even the simplest collision detection is added in, then Unity's physics seems to be orders of magnitude faster than by scripts could ever do.

avatar image agamedesigner · Aug 09, 2012 at 03:24 PM 0
Share

Eric, looking at your answer I was thinking that maybe it would be more efficient for me in my game to replace a CharacterController with some kind of rigidbody setup. But I'm not sure if that would behave properly. So what do you think would be the best and most efficient alternative to a CharacterController? I'm on iOS Pro, btw.

avatar image
1

Answer by jon.creighton · Dec 07, 2011 at 10:58 PM

This developer has done some comparisons of Box2D running in Cocos2D and PhysX running in Unity and found that for the same 2D test scene Box2D is roughly twice as fast as PhysX.

http://flyclops.com/battle-of-the-ios-physics-engines-197#comment-114

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 duck · Apr 22, 2010 at 08:43 PM

I've often wondered about this comparison too. I've seen a lot of 2d physics games which use the 3d engine constrained to 2 dimensions, but I've never seen any performance comparisons which weigh that up against using a scripted 2d-only physics engine.

I would say if your game is genuinely only 2d circle-circle collisions & responses, a roll-your-own approach could possibly perform better. This is a guess though, and would largely depend on how you implemented your 'early-out' techniques for limiting the number of distance tests (eg, by using a large 2d grid of 'bins').

If you were to also require other arbitrary 2d shapes for collision, I'd be much less confident, but like I said, I've never seen the two methods compared for performance side-by-side. I'd be very interested to see your results.

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 e-bonneville · Apr 22, 2010 at 08:44 PM

Well, performance isn't a huge issue, unless you're planning on having lots of gameObjects. So, yes, it's worth having colliders. Rigidbodies are also good, and turning off settings doesn't really effect performance, as I said before, unless you're working with large amounts of objects.

In fact, you can disable all the settings and work with rigidbody.AddForce to simulate gravity, and add forces on collision, which you can figure out using collision info and the connected rigidbody.

Also, scripting your own physics isn't worth the time when you have the Ageia PhysX physics engine at your fingertips.

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 Squeegy · Apr 22, 2010 at 09:06 PM 0
Share

30 ships + 90 projectiles on an iPhone. Does that count as "a lot"?

avatar image
0

Answer by jon.creighton · Dec 07, 2011 at 10:58 PM

This developer has done some comparisons of Box2D running in Cocos2D and PhysX running in Unity and found that for the same 2D test scene Box2D is roughly twice as fast as PhysX.

http://flyclops.com/battle-of-the-ios-physics-engines-197#comment-114

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 SoldierofYHVH · Apr 12, 2018 at 03:27 AM 0
Share

That page no longer exist!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Object Flies into Air Upon Collision, or goes through hill depending on isKinematic settings 1 Answer

How to setup character Collisions? 2 Answers

Realistic collisions with a kinematic rigidbody? 1 Answer

is there a way to move a rigidbody with something like moveposition without clipping through collider? 1 Answer

How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 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