- Home /
Use a capsule collider as a trigger to change a boolean statement.
I have a zombie that seeks the player; however, I would like to use a capsule collider in order for the zombie to tell whether or not if the player is in attacking range. I just need to know how to detect the player colliding with the zombies collider, and for that to change a boolean attacking value to true when the player is colliding. If you can please provide a tutorial that is in c#. Thank you in advance!!
What is attacking range? I mean how are you calculating range of zombie to attack, Your collider is your range? or are you checking distance or something else?
Answer by Fingerlights · Apr 12, 2016 at 10:55 PM
Hey! I'm extremely new to coding, so maybe I don't understand the question fully, but I believe I can help you, and I want to give back to Unity Answers, as it's helped me a lot!!!
I believe you want something like this
OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("player"))
{
attackBool = true;
}
}
OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("player"))
{
attackBool = false;
}
}
Make sure on your player, in the inspector (near the top) you add the tag "player" to it, and the capsule collider is set as "trigger"
Sorry if I'm completely wrong, as I said, I'm new to this, but I think this does what you need, and I want to help if I can!
Are you still trying to work it out? did this help at all? :D
Your answer
Follow this Question
Related Questions
How to check rotations 1 Answer
Changing default animation of AI third person controller to walk? 0 Answers
How to animate a enemy when he is following 0 Answers
Can the animation editor create local rotational data? 3 Answers
How to determine the direction an object is moving relative to itself? 3 Answers