• 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 lotzi11 · Oct 05, 2014 at 11:10 PM · collisionbounds

Applying the Bounds class to a Sphere without using the Collision class

I am trying to set up a bounds for a sphere made using gameObject to use to detect when the sphere intersects the ground. This is what my code looks like so far

     public class Particle{
         public GameObject sphere;
         public Bounds sphereBound;
     }
     
  Particle aSphere = new Particle();
  aSphere.sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  float radius = Random.Range (0f, 0.5f);
  aSphere.sphere.transform.localScale = new Vector3 (radius, radius, radius);
  aSphere.sphere.transform.position = new Vector3 (0f, 10.0f, 0f);    
  aSphere.sphereBound = new Bounds (aSphere.sphere.transform.position, aSphere.sphere.transform.localScale);
  aSphere.sphere.transform.parent = transform;    
                             

Is this the right way of adding Bounds to my sphere or is there something I'm missing? Also, this is a project in which I have to figure out the collision detection myself instead of using the classes in Unity so I am not allowed to use the Rigidbody or Collision class.

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 robertbu · Oct 05, 2014 at 11:18 PM

The code you have will correctly build a bounds for the sphere at the point of creation (like you have here). There are some issues:

  • If you are trying to update the bounds due to object size changes you may have trouble if the parent (transform) does not have localScale of (1,1,1).

  • You will need to update the bounds.center each time the object is moved.

  • Using bounds for detecting collisions will produce false positives and make applying the force for the collision difficult. For example, say the corners of two bounds brushed each other. You would detect a collision, but the object would not have touched.

If all of your objects are spheres, it would be better to save the world radius of each 'Particle'. Then say you had the transforms of two objects, t1 and t2, and the radius of each object r1 and r2. You would know if they collided if:

  if (Vector3.Distance(t1, t2) < r1 + r2) {
      Deubg.Log("The two objects collided");
  }


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.

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

2 People are following this question.

avatar image avatar image

Related Questions

Check if an Object is intersecting any other object 0 Answers

Unity Height Glitch (explained) 1 Answer

What's the best/easiest way to do something like Bounds.Intersects but accounting for rotation? 1 Answer

Simple example bound box or get the top position gameobject 1 Answer

check box overlap / colliders in edit mode 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