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
0
Question by ckho92 · Feb 06, 2017 at 03:29 PM · collisioncollidercollision detectioncollider2dcollision2d

How to set collision for an object with specific collider size?

alt text

Hello guys, i am creating a gameobject with above image, white circle with a small red circle, i just want to set the collision setting for red circle ONLY, i add the circle collider 2D for red size only.

But when i try to play on debug mode, object collider with the white circle will still trigger the collision.

How can i collide to red circle only without changing the gameobject? Thank you.

player-mspaint.png (799 B)
Comment
Add comment · Show 1
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 ckho92 · Feb 07, 2017 at 03:16 PM 0
Share

alt text

Here are my information for the circle setting (the red pot set as collider) and the setting for the bullet

alt text

player-information.png (98.1 kB)
bullet-information.png (46.9 kB)

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DoctorMoney · Feb 06, 2017 at 06:52 PM

 OnCollisionEnter(Collision collision){
 
      if(collision.collider.gameObject.tag == "yourTagHere")
            {
                     //DoStuff
             }
 
 }

Something like that, add a tag to the red collider so that when the player or whatever collides with it, the script doesn't do anything until the current collisions tag is the same as the red tag. Doing it off size would be tough.

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 ckho92 · Feb 07, 2017 at 03:17 PM 0
Share

thank you for help tried but still fail :'(

avatar image
0

Answer by Pitiedowl · Feb 07, 2017 at 01:33 PM

I dont know if this is exactly what you want but when you selected your object with the colider that you want to change, there should be in the inspector an option with a few squares with a line connecting them. Click on that and you should be able to see a green box showing around the object. You will then be able to see little dots within the middle of each face of the collider. You can change the scale of the collider by using those dots. Again i dont know if this is what you want but there ya go :D

Comment
Add comment · Show 3 · 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 ckho92 · Feb 07, 2017 at 03:16 PM 0
Share

thank you and i know what you means, i already set up as the above picture. but i still can't set the collision right.

avatar image Pitiedowl ckho92 · Feb 07, 2017 at 06:30 PM 0
Share

The guy above my question had the right idea as to use the tags and have the code to only allow collision via that certain tag. you have to elaborate on his code, from what I can tell that would do the trick

avatar image ckho92 Pitiedowl · Feb 08, 2017 at 01:13 AM 0
Share

Yes i tried to use his method, but the collision code didn't work or even triggered!

Here are my code,it triggered when the collision touches the white region. But i just want to triggered when the collision touches the red region(collider).

  private void OnCollisionEnter2D(Collision collision){
  
       if(collision.gameObject.layer == Layer$$anonymous$$ask.NameToLayer("yourTagHere"))
             {
                      //DoStuff
              }
avatar image
0

Answer by ckho92 · Feb 08, 2017 at 02:44 PM

Ok it works now! Tried to set both item as is a trigger and using the following coding.

     private void OnTriggerEnter2D(Collider2D other)
     {
         if(other.gameObject.layer == LayerMask.NameToLayer("enemy"))
             Destroy(this.gameObject);
     }

Reference: https://github.com/unity3d-jp-tutorials/2d-shooting-game/wiki/%E7%AC%AC05%E5%9B%9E-%E5%BD%93%E3%81%9F%E3%82%8A%E5%88%A4%E5%AE%9A%E3%81%A8%E3%82%A2%E3%83%8B%E3%83%A1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%81%A8%E3%83%AC%E3%82%A4%E3%83%A4%E3%83%BC

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

6 People are following this question.

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

Related Questions

Collision detection problem 0 Answers

I am trying to create all elements in the scene from one script at run time. How do I detect collisions between the enemy and the coin without having to create another script for each item? 0 Answers

OnTriggerEnter2D working, OnColliderEnter2D not working 1 Answer

How do I detect which collider is being collided with? 0 Answers

Sprites collision not working on high speeds 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