- Home /
2D collision detection without rigid body?
I have a simple game where I require a certain amount of collision detection from my models. However, I do not need physics in this so the checks are actually mostly just box checks or shape checks which need to trigger an event.
I got it to work using RigidBody2D + BoxCollider2D on the colliding object and BoxCollider2D (With isTrigger set to true) on the other one.
I do my translations currently using translate rather than physics (Time will tell whether I will do it like this in the end as well).
So my question is that is there a way to clip the Rigid Body out of the whole equation. I feel like the current model is a bit silly given that I have a Fixed Angle rigid body (All game characters will be like this and there might be many so this creates overhead?) objects with all the variables set to 0.
Answer by Spinnernicholas · Dec 28, 2013 at 06:10 PM
Yeah, you can drop the rigidbody and just do everything with colliders. Then you can respond to events OnTriggerEnter2D, OnTriggerStay2D, and OnTriggerexit2D.
Hey man, I tried those mothods using only colliders, but it just wont work.
The only way I managed to make it work is using a rigidbody as $$anonymous$$uhwu said. Can you elaborate a bit more on how you have done?
Yes I'm using the new classes for 2D content. Right now the game is behaving as I want, but like I said, it's weird being forced to attach a rigid body. Before I found this post I already felt like I should be able to do it with colliders and those methods you pointed out, basically after you post I just retested everything I had already done hehehe.
Yeah, that verifies it, one of the two objects needs to have a rigid body. You can just have rigid bodies on you characters/entities and not on your environments.
I don't know why he selected my answer if it doesn't work.
Answer by DiegoGomez87 · Aug 03, 2016 at 06:38 AM
Hi, Maybe this is not the best approach and probably you are not expecting this answer anymore, but someone like me could reach this thread and this could be useful for him: If you add a rigidbody with "Is Kinematic" = true and set the box collider with "Is Trigger" = true you can detect collision using the following code:
void OnTriggerEnter2D(Collider2D other) { }
Hope this help
Answer by JiajieXu · May 26, 2017 at 04:17 PM
The answer of Spinnernicholas is not correct!
You need at least one rigidbody2D attached in the collision of two colliders.
To improve the performance is a good practice attaching the rigidbody2D to the moving gameobject, and leave the static collider without rigidbody.
some useful links are: