void OnCollisionEnter2D(Collision2D other) {
Debug.Log("Test");
if (other.gameObject.tag == "Boundary")
return;
if (Array.FindIndex<string>(Properties.Tags_Damaging, x => x == other.gameObject.tag) >= 0) {
// the other object can be hit.
Destroy(other.gameObject);
}
if (Properties.Explosion_Prefab)
Instantiate(Properties.Explosion_Prefab, other.contacts[0].point, Quaternion.identity);
}
the Laser Code:
void OnCollisionEnter2D(Collision2D other) {
Debug.Log("test");
if (other.gameObject.tag == "Boundary")
return;
if (other.gameObject.tag != Tag_Owner) {
// particle effects
if (Properties.Explosion_Prefab)
Instantiate(Properties.Explosion_Prefab, transform.position, Quaternion.identity);
// destroy
Destroy(gameObject);
}
}
Try turning off isKinematic. For some reason isKinematic also disables collisions and triggers when used in 2D. It’s been causing me trouble too, as there currently is no easy way to trigger between two objects that are kinematic.
but for some reason, my objects are being moved without any code to do it or gravity to affect them. Well… one problem goes, another comes… hehehe. aahh :sad:
#Edit#
My Boundary which check the limits! him is the problem. I’m using a Cube covering all the playable area (without mesh, only collider), so that way i can use Parallax bounds. When a object touch the limit, it is transported to the otherside (exemple: reach the right limit, you get to the left limit). I check this using OnCollisionExit.
If there is an object inside other collider, it will be moving. I’ll have to change my Parallax limits idea.
Also if you change scale property of 2D sprite then collision get messed up and physics start feeling jerky. I heard there is a problem with box2d and Unity transform property change but not sure.
I know your answer was not correct for the OP, since they didn’t have that option back then, but this solved a big headache for me yesterday. Thank you!
Things like this can really be frustrating, being that upgrading one of 2D games made to a higher version of Unity, I guess you would expect things to break, but after 1.5 hrs of debugging why my 2D collisions just don’t work, I simply tick the box “Use Full Kinematics Contacts” and it works like it should.
I should refer to the manual much more often, and sooner rather than 1.5hrs later:
I’m not sure I follow. Are you saying that this option was on for a certain Rigidbody2D prior to upgrading then after it was turned off? I don’t see how that can happen TBH; this would be the first time I’ve seen it reported. This option isn’t a “fix” for anything so I’m confused over your comment.
@MelvMay I can’t tell you whether this tick box was enabled or not prior to upgrading, I have to assume it was, as my collision detection was working with no issues, and then just stopped working after upgrading. As for your quote “This option isn’t a “fix” for anything”, I guess if you say so, but it did fix my issue. Could you elaborate beyond the documentation what it is for?
Normally Kinematic vs other Kinematic/Static body-types don’t produce contacts (only vs Dynami). When it’s on the system calculates them for you meaning the Kinematic in question produces contacts like a Dynamic body-type but still acts like a Kinematic body i.e. no geavity, forces or collision response.
Again though, a contact doesn’t mean a collision response though. For instance, triggers produce contacts but there’s no collision response. What you will get with this option are callbacks and the ability to use GetContacts.
To any other n00bs like me, if you’re using kinematic mode you probably want On**Trigger**Enter2D instead.
Or switch to Dynamic if you want to use OnCollisionEnter2D
“Collision” is explicitly meant for things bonking into each other, which you probably don’t want if you’re not making something with physicality that responds to forces
The body type (Static, Kinematic or Dynamic) has nothing to do with the Trigger/Collision callbacks doesn’t change them. If a collider is set as a trigger then you’ll get “trigger” callbacks but if not you’ll get “collision” callbacks.
Hi! I tried almost every solution provided in this thread and still no results. I’ll attach the trigger code below and some screenshots of my inspector options. Oh and btw I’ve started Unity development just a week ago so I’m a pretty big noob.
Please, don’t hijack existing threads with what you assume is the same issue, just create your own thread; it’s free and easy. Often these threads get filled with lots of posts, all different but the title sounds the same so they act like a problem magnet.
Also, you don’t state how you know it’s not calling that trigger. This happens SO many times. No console message because it’s buried inside other logic. It’s not testing if the callback happens, it’s testing if the callback happens AND other logic is working. Put the debug log as the first thing if that’s what you’re testing for or learn how to attached a debugger which is an essential skill moving forward.
Then there’s the “Do you have them set to contact in the Layer Collision Matrix”? This is all stuff I presume you’ve covered in a basic 2D physics tutorial?
Nothing in your script above shows an obvious problem apart from what I’ve said above although it’s not clear why you’ve set all the constraints on. A Kinematic body will only move how you tell it to; it’ll not react to collisions. No need to constrain rotation if you don’t ask for rotation. No need to constraint X or Y if you don’t ask it to move in X or Y.