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
1
Question by DeadShawn · Oct 10, 2014 at 09:34 AM · 2dphysics3d

How to use 2D physics for 3D models

Hello. I'm making a game that uses 3D models, but to increase performance I planned on using 2D physics. However, when I try to add a BoxCollider 2D it doesn't show up in the scene, and I get the error "The collider did not create a collision shape as it failed verification. This could be because it was deemed too small or its vertices were too close. Vertices can also become close under certain rotations."

I tried making my model bigger, but that didn't solve the issue. Do I have to use 3D physics for 3D objects?

[edit] I've found a really hacky work around. If use 3DSMax to render a png of the model, then attach a sprite-render to the object, create the 2d physics polygon, then delete the sprite-render I get the desired results. Surely there is a better way of doing this?

[edit2] I found the reason this is happening. When applying a BoxCollder2D to a 3D object, unity seems to take a flattened image of the object from the Z plane (that is to say, with Y being vertical and X being horizontal) but I was rotating my objects by 90 degrees, making that plate on which it's trying to make the collision box flat:

http://i.imgur.com/AIg6v5q.png (worked on the left, error on the right)

I'm still not sure how to fix this, but at least I have something to work from now. I guess I could open the models in 3D studio and rotate them there, then export them again.

Comment
Add comment · Show 3
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 bubzy · Oct 10, 2014 at 09:37 AM 0
Share

"to increase performance", what exactly is your game doing that it requires this?

there are better ways to increase performance than trying to hack a solution, identify where the performance leak is first and address that.

avatar image DeadShawn · Oct 10, 2014 at 09:47 AM 1
Share

The problem is the number of simulated bodies. With the 2D physics engine I can get about 2000 without slowdown, but with the 3D physics engine it was starting to slowdown around 1000.

avatar image Kiwasi · Oct 10, 2014 at 10:00 AM 0
Share

I believe your hacky way is the best approach. The 2D physics system was designed to create colliders based on the sprite mesh. You give it a 3D mesh to start with and it gets confused.

You can probably make an editor script that takes a 3D model, grabs the vertices, calculates the furthest out, flattens it to a 2D mesh, then hands it to Unity to create the polygon collider from.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kiwasi · Oct 10, 2014 at 09:51 AM

You should be able to add a 3D object as a child of a RigidBody2D. At worst case you can attach a script to your model that makes it follow the RigidBody2D. You will probably have to build custom colliders to get it to match your model.

In terms of performance I don't think you will end up gaining much, if anything. I'm only listing this as a solution because I can come up with a couple of cool concepts using a 2D game with 3D graphics, or vice versa. But you need to build it in as a designed mechanic, not a performance boost.

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 Eric5h5 · Oct 10, 2014 at 09:57 AM 1
Share

2D colliders are generally somewhat faster than 3D colliders, so it's a reasonable optimization if the physics are all going to be 2D anyway. (Just don't expect it to be massively faster.)

avatar image
0

Answer by Josh Naylor · Oct 10, 2014 at 09:35 AM

Edit: Apparently so.

Comment
Add comment · Show 7 · 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 DeadShawn · Oct 10, 2014 at 09:52 AM 0
Share

Hmm then I guess I was mistaken. I thought there was no difference between 2D and 3D projects, that sprites were simply quads. Just that the 2D and 3D physics couldn't interact. Which would have been ok, because I didn't need them to. I didn't want ANY 3D physics.

avatar image Eric5h5 · Oct 10, 2014 at 09:54 AM 0
Share

You can certainly add 2D physics to 3D objects; all objects are 3D objects after all. The collider you add to an object doesn't have to be related to the mesh in any way and is a totally separate component.

avatar image Kiwasi · Oct 10, 2014 at 09:55 AM 0
Share

You are close. There is not much difference. Sprites are not quads, they are custom meshes built to reduce the transparent area on sprites. This helps reduce overdraw. But the idea is essentially the same.

avatar image Eric5h5 · Oct 10, 2014 at 10:11 AM 0
Share

Well, sprites are usually quads. If you have Pro, you have the option of making sprites be a tight mesh, or a quad. If you have Free, they are always quads.

avatar image Kiwasi · Oct 10, 2014 at 10:20 AM 0
Share

@Eric5h5 Are you sure? I thought the mesh optimisation was available on free. I'll play with it later.

Show more comments
avatar image
0

Answer by Eric5h5 · Oct 10, 2014 at 09:53 AM

Sounds like the scale of the model is way off. The box collider should ideally be about 1 unit in size.

Comment
Add comment · Show 4 · 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 DeadShawn · Oct 10, 2014 at 10:03 AM 0
Share

The model I was trying to add it to was about 2x1x1 (but let me double check to be sure)

But you're saying I should be able to apply the BoxCollider2D directly to a 3D mesh?

avatar image Kiwasi · Oct 10, 2014 at 10:05 AM 0
Share

You should be able to apply a box collider directly.

avatar image Eric5h5 · Oct 10, 2014 at 10:12 AM 0
Share

Also you can always change the size of the box collider in the inspector.

Technically, you add a box collider component to a GameObject. You can also add mesh filter and mesh renderer components to a GameObject. So you don't really add a box collider to a mesh.

avatar image DeadShawn · Oct 10, 2014 at 10:24 AM 0
Share

The problem was/is if you rotate the mesh by 90 degrees, unity is building a collider with a size of 0 on the X axis. I think I may need to rotate all of my models then re export them.

Thank you for the help by the way!

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

7 People are following this question.

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

Related Questions

Objects stuck dragging across floor 1 Answer

Using a sprite sheet in a 3d enviroment? 0 Answers

Physics - strange jumps. 2 Answers

Is it required to use 3D physics when a 2D game uses the z axis? 1 Answer

Should 2.5D use 3D or 2D settings ? 3 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