- Home /
Troubles with "isTrigger"
Hi, good morning. I've seen a lot of questions with related topics but at the end, I'm not finding a solution which I know it will be actually stupid... I'm setting up a 2D scene which has:
A background with a collider2D at the bottom (the floor).
One zombie acting as a player, you can move him left and right.
An ord of zombies coming from the right which are enemies.
I want to allow the player to walk through the enemies and attack whenever he wants. The thing is that when I'm activating the 'isTrigger', the player is automatically falling from the platform (because he's colliding with it, you can see him falling on the photo). I tried to put Kinematic and yes, the enemies can pass over it and it doesn't fall but it's not the objective because with this case you cannot move the player. What should I do? I feel that I'm wasting too many hours with this...
You can move the player when Is$$anonymous$$inematic is on. (get a look at this method : https://docs.unity3d.com/ScriptReference/Rigidbody.$$anonymous$$ovePosition.html )
Answer by Ermiq · Aug 17, 2018 at 11:13 AM
You could put your enemies in their separate layer and set your player collider to ignore collisions with objects in that layer. Here's a script you could use: https://forum.unity.com/threads/ignorecollision-by-layer.3226/
but will this not cancel out any trigger interaction between these layers as well?
Hm... Yes, you're right. Then maybe use 2 colliders on player zombie: first one for rigidbody physyics and set it to ignore enemies layer, and second one set to 'IsTrigger' for the fights. Say $$anonymous$$ovingCollider = GetComponent<CapsuleCollider2D> (); TriggerCollider = GetComponent<BoxCollider2D> ();
Answer by Captain_Pineapple · Aug 17, 2018 at 10:30 AM
Hey there,
well there is a solution that comes to my mind but it's most certainly not the most pretty one:
Give your enemys as well as your normal character each a trigger collider and a normal collider. Then whenevery ou spawn an enemy you call the function Physics2.ignoreCollision with the normal colliders of your character and the enemy.
This should render all "normal" collisions obsolete and will still enable you to walk on the ground. The ugly point about this is: You really have to make sure to call an ignore collision between all your players colliders and all your enemey colliders each. If you forget one that will result in strange things and probably will be difficult to debug.
Should in theory solve your problem though. Good luck with your game, graphics look neat :)
Your answer

Follow this Question
Related Questions
Trigger Collider Getting Left Behind Object 1 Answer
Moving many 2D triggers is slow. Why? 1 Answer
Animation triggers are not firing 0 Answers
Trigger only one collider? 1 Answer