- Home /
How to make triggers collide with player?
I have all my code in the player object, when the player collides with the door and has 2 keys then the door will disappear and a new sprite will take its place that looks like the same door but its open instead.
Well... thats what should happen. I have checked the box in the closed door object the says Is Trigger and started to test it but when i walk to the door without any keys or just one i go straight through the door without it even changing to and open door, but when i have 2 keys and walk to the door it changes correctly.
So my question is how do i make objects that have Is Trigger checked still collide with other objects?
Thanks in advance!
Answer by aldonaletto · Aug 31, 2014 at 04:31 PM
Your question isn't clear enough. What's exactly the problem? Do you want to know how to make the door "solid" until the player has got two keys? A possible solution is to use two objects, a trigger and a collider: detect when the player enters the trigger, check whether it has the two keys, and if so delete the collider object and replace the sprite. NOTE: the trigger must be bigger than the collider (say, 0.2 to 0.3 meters on each side) in order to react to CharacterControllers.
yeah thats what i want to do but how would i turn off the collider when i walk to the door with the keys
Don't set IsTrigger in the door's collider: child a cube to the door, adjust its dimensions to cover the area you want, uncheck the Renderer component to make it invisible and check the cube collider's Is Trigger checkbox. In some player's script, add a code like this:
function OnTriggerEnter(other: Collider){
if (other.CompareTag("Door") && playerHas$$anonymous$$ey1 && playerHas$$anonymous$$ey2){
Destroy(other.transform.parent.gameObject);
}
}
Obviously, the cube must be tagged as "Door", and you must have two boolean variables playerHas$$anonymous$$ey1 and playerHas$$anonymous$$ey2 that are set when the player get the keys (or whatever variables you're currently using to know whether the player has got the keys).
Answer by BMayne · Aug 31, 2014 at 04:57 PM
Hey There,
A trigger is a collider that does not have collision (as in blocks movement). If you want a trigger zone you do what aldonaletto was saying. Have one box collider as your door and a second one as the trigger.
Your answer
