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
0
Question by camtronius · Apr 21, 2014 at 03:49 AM · collisiononcollisionenterrtsspherecollider

Detecting Collisions with Sphere Collider

Hey Guys, I am trying to detect a collision with a sphere collider in my game, but am having a difficult time finding information on it. What I have is : A cylinder with an added "Sphere Collider" Component (added through the gui "Add component"). A block called "Unit" which is going to be colliding with the sphere collider. I am trying to make the sphere collider attached to the cylinder print a message when the block enters the collider field. I looked at the documentation and dont know what to do with the code:

 public class Tower : MonoBehaviour
 {
     // Update is called once per frame
         void Update ()
         {
         }
 
         void OnCollisionEnter(Collision col) {
             if(col.gameObject.name=="Unit"){
             Debug.Log(col.gameObject.name);
             }
         }
     }


 Anything would help guys. Thanks,
Comment
Add comment · Show 4
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 xortrox · Apr 21, 2014 at 04:19 AM 0
Share

This should work just fine as long as you make sure Units have a RigidBody component. Also if you're spawning unit prefabs make sure you name them "Unit" as instantiated prefabs usually get a (clone) suffix "Unit(clone)"

avatar image camtronius · Apr 21, 2014 at 06:06 AM 0
Share

@xortrox for some reason it still isnt working. Cylinder is a rigid body, Unit is a rigid body. Cylinder has the collision sphere attached to it, but still not luck. It wont print out any statements, so I know its not detecting the collision... $$anonymous$$now any good examples? --I should also mention that I have the sphere collider set to a trigger. Thanks,

avatar image robertbu · Apr 21, 2014 at 06:14 AM 0
Share

If you are using triggers, then you need to use OnTriggerEnter() ins$$anonymous$$d.

avatar image Burla · Apr 21, 2014 at 08:13 AM 0
Share

Could one of you post it as an answer and then @camtronius can approve it as an answer. That way the ForumBot won't keep pushing this thread up in the stack. :-)

1 Reply

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

Answer by camtronius · Apr 21, 2014 at 06:34 AM

@xortrox I actually solved it. I was wanting the ontriggerenter function and changing the parameters to collider! Thanks man,

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

22 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

Related Questions

Delayed Collisions Bug (includes video demonstration) 1 Answer

Boo & Collision 1 Answer

Why is my OnCollisionEnter function working for enemies and not my player? 1 Answer

Checking Object Collision Without Script 1 Answer

Ammo crate collision 2 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