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 dansav · Oct 01, 2015 at 05:29 PM · spheremeshcolliderconvexhollow

Create hollow sphere with objects bouncing around inside

I want to make a sphere with atoms bouncing around inside. I started with a sphere and then used mesh maker plugin on the asset store to change the orientation of the triangle faces. (flip the normals) and/or make the mesh double sided. I tried using a mesh collider and put a smaller sphere with a sphere collider inside the larger sphere. The smaller sphere just falls right through the larger sphere.

And it gives the error: Serialization depth limit exceeded at 'ceometric.ComputationalGeometry::MeshEdge'. There may be an object composition cycle in one or more of your serialized classes.

If I click meshcollider convex: it gives an error of cannot exceed 255 polygons.

How can I make objects inside the sphere bounce around inside the sphere?

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 DaDonik · Oct 01, 2015 at 06:15 PM

Sadly It's not possible to make a physics object act as a hollow sphere.

You could make a hollow sphere within your favourite 3D modelling program and split it in multiple parts that have less than 255 polygons each.

I don't know if you need to move/rotate the hollow sphere, but if it's static you could use a bunch of box colliders and align them to represent a sphere. This will probably be faster than convex mesh colliders, at least if you don't need to move/rotate all those box colliders every frame.

Note that the 'walls' of your hollow sphere should have a certain width, to prevent fast moving atoms from penetrating it.

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 _Gkxd · Oct 01, 2015 at 07:32 PM

There is an analytic way of calculating a collision between a point and a boundary of the sphere.

Let the center of your sphere be C (Vector3) and let the radius of the sphere be R (float).

A (spherical) atom with position P will be inside the sphere is

 (C - P).sqrMagnitude <= R*R;

An inward facing normal vector at that point on the sphere is

 C - P // No need to normalize because we will be using this to define a plane for reflection

To bounce the atom back once it collides, all you have to do is reflect its velocity using the plane defined by the above normal vector

 rigidbody.velocity = Vector3.Reflect(rigidbody.velocity, C-P);

Here is a pseudocode example that will make atoms bounce inside a sphere (attach to each atom):

 public Vector3 C; // Sphere center
 public float R; // Sphere radius
 public Rigidbody atomRigidbody; // Rigidbody of the atom

 void FixedUpdate() {
     if ((C-P).sqrMagnitude > R * R) {
         atomRigidbody.velocity = Vector3.Reflect(atomRigidbody.velocity, C - P);

         // Put the atom slightly inside the sphere so that it doesn't collide right after
         atomRigidbody.position = C + (P-C).normalized * R * 0.999f;
     }
 }

Note that this method knows nothing about the shape of the atoms, it only cares about the position of their centers.

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 dansav · Oct 01, 2015 at 07:48 PM 0
Share

Thanks for the idea and pseudocode. I can try this if the breaking the mesh into pieces does not work.

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

29 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

Related Questions

how add cylinder with rigid body inside a sphere with rigid body? 0 Answers

Convex MeshCollider Doesn't Work on 2D Plane 0 Answers

Rigidbody and convex mesh collider 1 Answer

Raycast on Nonconvex MeshCollider 1 Answer

Non Convex Mesh Colliders even though there aren't any 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