- Home /
How to set collision for an object with specific collider size?
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.
Here are my information for the circle setting (the red pot set as collider) and the setting for the bullet
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.
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
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.
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
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
}
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);
}