- Home /
OnTriggerEnter Issue?
ok so im totally stumped... I have a helper creature in my game that targets an enemy goes to them and then the enemy dies on contact, and an enemy that comes to the main character then blows up and does damage. they both work perfectly, all on trigger functions work on both of them with every other creature they encounter until they run into each other. the enemy guy should die and its not even registering a collision between the two. my helper just starts spinning very fast circles around/inside the enemy. I thought maybe i had a typo with the tag so i copied it directly from a enemy he was destroying and still no luck. here is my code if anyone can help me spot a problem. its the when hes hit by "HelperM". its not printing or anything. both guys have box colliders. Is there a better way to be detecting collisions or any suggestions how to find/fix the issue?
void OnTriggerEnter(Collider hit)
{
if (hit.gameObject.tag == "ffball")
{
dt = 50;
damage = true;
DamageFromPlayer();
}
if (hit.gameObject.tag == "feball")
{
dt = 35;
damage = true;
DamageFromPlayer();
}
if (hit.gameObject.tag == "DeathWorm")
{
dead = true;
}
if (hit.gameObject.tag == "fbullet")
{
dt = 35;
damage = true;
DamageFromPlayer();
}
if (hit.gameObject.tag == "HelperM")
{
dead = true;
print("Got Hit By HelperM");
}
}
Answer by meat5000 · Mar 29, 2017 at 04:32 PM
Looks like you should have at least 1 rigidbody (non-K) and OnCollision routines... not triggers.
I tried using OnCollision but was having the same outcome with those. Ill change the code to that because it does make more sense, but still doesn't solve the issue. what did you mean by having a rigidbody (non-k)? that is something i haven't tried but kinda confused with what exactly your suggesting?
Thank you, I tried adding a rigidbody and that solved the issue.
No problem. Non-$$anonymous$$ is non-kinematic. This means it responds to physics. $$anonymous$$inematic bodies kinda hang in space and are not freely movable objects.
Your answer
Follow this Question
Related Questions
Could some one help me with this script... 5 Answers
OnTriggerEnter not working in running game 4 Answers
Destroying object on collision 3 Answers
Can I have a single rigidbody2d that acts as both collider and trigger? 1 Answer
Objects don't collide 1 Answer