- Home /
Enemy falling through floor when i have a rigidbody and a collider set to trigger
I googled it a lot but i was unable to find a solution to this.
i have an enemy and i attached Rigidbody2D to it, it patrols an area and has to go up and down slopes, that's why the rigidbody2d is attached, to use gravity.
At the same time a want to use with it a CircleCollider2D as a trigger, to have combat.
I need my player to pass through this enemy.
But at the moment i set the collider as a trigger my enemy falls through the floor.
The floor also has a composite collider on it and a rigidbody2d.
There is any way to work around this?
ps: i'm using c# if i need any coding.
Answer by Piyush_Pandey · Jul 20, 2018 at 06:29 AM
If an object is having a collider with IsTrigger enabled, it will not act as a solid shape even though the rigidbody is attached. Instead it will work as a trigger volume. What you can do is:-
1) Create an empty child of player
2) Attach another CircleCollider2D to it and mark it as isTrigger enabled.
3) Use this for triggering the enemies.
4) Disable the isTrigger of the players main collider.
EDIT: sorry i missed the Enemy Part. For that you can add different layers to Player and enemy. You can check here. Now got to the project settings->physics2D and disable the collision between the Player and the Enemy layers. In this way, they will not collide with each other.
Fantastic! Now it worked! i was already using layers but forgot about the physics 2D in the project settings. i placed a empty object with a trigger collider as a child of the player and the combat is still working too.
Answer by tallesmaziero · Jul 20, 2018 at 06:42 AM
Thx for your reponse.
I've already tried to do this, but the problem is that my player pushs the enemy and i can't pass through it.
$$anonymous$$aybe if i can enable gravity without a rigidbody on my enemy it will work. but i don't know how to do this without a rigidbody or a character controller.
You can add multiple Collider to a Object! One for the Trigger, one for the collision
I tried that. But it don't resolves the problem of not passing through my enemy. The "not trigger" collider prevents it.
Your answer
Follow this Question
Related Questions
Apply Rigidbody/Colliders on EventSystem or Prefab Itself? 0 Answers
2018.2.17 OnTriggerEnter2D not working 1 Answer
[SOLVED] How to Destroy a rigidbody game object on collision with another gameobject? 4 Answers
Turning off trigger with multiple box colliders? 0 Answers
Is there any way to increase a triggers check rate? 2 Answers